2015-04-30 12:30:03 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* Adds and controls pointers for contextual help / tutorials
2015-04-30 12:30:03 +00:00
*
2015-08-07 13:37:45 +00:00
* @ author WooThemes
* @ category Admin
2020-08-05 16:36:24 +00:00
* @ package WooCommerce\Admin
2015-08-07 13:37:45 +00:00
* @ version 2.4 . 0
2015-04-30 12:30:03 +00:00
*/
if ( ! defined ( 'ABSPATH' ) ) {
exit ;
}
/**
2015-11-03 12:28:01 +00:00
* WC_Admin_Pointers Class .
2015-04-30 12:30:03 +00:00
*/
class WC_Admin_Pointers {
/**
2015-07-06 09:45:10 +00:00
* Constructor .
2015-04-30 12:30:03 +00:00
*/
public function __construct () {
add_action ( 'admin_enqueue_scripts' , array ( $this , 'setup_pointers_for_screen' ) );
}
/**
2015-07-06 09:45:10 +00:00
* Setup pointers for screen .
2015-04-30 12:30:03 +00:00
*/
public function setup_pointers_for_screen () {
2016-02-05 12:16:41 +00:00
if ( ! $screen = get_current_screen () ) {
return ;
}
2015-04-30 12:30:03 +00:00
switch ( $screen -> id ) {
2018-03-05 18:59:17 +00:00
case 'product' :
2015-04-30 12:30:03 +00:00
$this -> create_product_tutorial ();
2018-03-05 18:59:17 +00:00
break ;
2015-04-30 12:30:03 +00:00
}
}
/**
2015-07-06 09:45:10 +00:00
* Pointers for creating a product .
2015-04-30 12:30:03 +00:00
*/
public function create_product_tutorial () {
if ( ! isset ( $_GET [ 'tutorial' ] ) || ! current_user_can ( 'manage_options' ) ) {
return ;
}
// These pointers will chain - they will not be shown at once.
$pointers = array (
'pointers' => array (
2018-03-05 18:59:17 +00:00
'title' => array (
'target' => '#title' ,
2015-04-30 12:30:03 +00:00
'next' => 'content' ,
'next_trigger' => array (
'target' => '#title' ,
2016-08-27 01:46:45 +00:00
'event' => 'input' ,
2015-04-30 12:30:03 +00:00
),
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Product name' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__ ( 'Give your new product a name here. This is a required field and will be what your customers will see in your store.' , 'woocommerce' ) . '</p>' ,
'position' => array (
'edge' => 'top' ,
2016-08-27 01:46:45 +00:00
'align' => 'left' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'content' => array (
'target' => '#wp-content-editor-container' ,
2015-04-30 12:34:51 +00:00
'next' => 'product-type' ,
2015-11-16 14:21:51 +00:00
'next_trigger' => array (),
2015-04-30 12:30:03 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Product description' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__ ( 'This is your products main body of content. Here you should describe your product in detail.' , 'woocommerce' ) . '</p>' ,
'position' => array (
'edge' => 'bottom' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'product-type' => array (
'target' => '#product-type' ,
2015-04-30 12:30:03 +00:00
'next' => 'virtual' ,
'next_trigger' => array (
2018-03-05 18:59:17 +00:00
'target' => '#product-type' ,
2016-08-27 01:46:45 +00:00
'event' => 'change blur click' ,
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Choose product type' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:34:51 +00:00
'<p>' . esc_html__ ( 'Choose a type for this product. Simple is suitable for most physical goods and services (we recommend setting up a simple product for now).' , 'woocommerce' ) . '</p>' .
2015-08-07 13:37:45 +00:00
'<p>' . esc_html__ ( 'Variable is for more complex products such as t-shirts with multiple sizes.' , 'woocommerce' ) . '</p>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__ ( 'Grouped products are for grouping several simple products into one.' , 'woocommerce' ) . '</p>' .
'<p>' . esc_html__ ( 'Finally, external products are for linking off-site.' , 'woocommerce' ) . '</p>' ,
'position' => array (
'edge' => 'bottom' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'virtual' => array (
'target' => '#_virtual' ,
2015-04-30 12:30:03 +00:00
'next' => 'downloadable' ,
'next_trigger' => array (
2018-03-05 18:59:17 +00:00
'target' => '#_virtual' ,
2016-08-27 01:46:45 +00:00
'event' => 'change' ,
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Virtual products' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__ ( 'Check the "Virtual" box if this is a non-physical item, for example a service, which does not need shipping.' , 'woocommerce' ) . '</p>' ,
'position' => array (
'edge' => 'bottom' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'downloadable' => array (
'target' => '#_downloadable' ,
2015-04-30 12:30:03 +00:00
'next' => 'regular_price' ,
'next_trigger' => array (
2018-03-05 18:59:17 +00:00
'target' => '#_downloadable' ,
2016-08-27 01:46:45 +00:00
'event' => 'change' ,
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Downloadable products' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__ ( 'If purchasing this product gives a customer access to a downloadable file, e.g. software, check this box.' , 'woocommerce' ) . '</p>' ,
'position' => array (
'edge' => 'bottom' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'regular_price' => array (
'target' => '#_regular_price' ,
2015-04-30 12:30:03 +00:00
'next' => 'postexcerpt' ,
'next_trigger' => array (
2018-03-05 18:59:17 +00:00
'target' => '#_regular_price' ,
2016-08-27 01:46:45 +00:00
'event' => 'input' ,
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'options' => array (
2016-08-27 06:14:06 +00:00
'content' => '<h3>' . esc_html__ ( 'Prices' , 'woocommerce' ) . '</h3>' .
2017-04-26 12:51:53 +00:00
'<p>' . esc_html__ ( 'Next you need to give your product a price.' , 'woocommerce' ) . '</p>' ,
2015-04-30 12:30:03 +00:00
'position' => array (
'edge' => 'bottom' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'postexcerpt' => array (
'target' => '#postexcerpt' ,
2015-04-30 12:30:03 +00:00
'next' => 'postimagediv' ,
'next_trigger' => array (
2018-03-05 18:59:17 +00:00
'target' => '#postexcerpt' ,
2016-08-27 01:46:45 +00:00
'event' => 'input' ,
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Product short description' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__ ( 'Add a quick summary for your product here. This will appear on the product page under the product name.' , 'woocommerce' ) . '</p>' ,
'position' => array (
'edge' => 'bottom' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'postimagediv' => array (
'target' => '#postimagediv' ,
'next' => 'product_tag' ,
2015-04-30 12:30:03 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Product images' , 'woocommerce' ) . '</h3>' .
2017-04-26 12:51:53 +00:00
'<p>' . esc_html__ ( " Upload or assign an image to your product here. This image will be shown in your store's catalog. " , 'woocommerce' ) . '</p>' ,
2015-04-30 12:30:03 +00:00
'position' => array (
2015-04-30 12:34:51 +00:00
'edge' => 'right' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'product_tag' => array (
'target' => '#tagsdiv-product_tag' ,
'next' => 'product_catdiv' ,
2015-04-30 12:30:03 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Product tags' , 'woocommerce' ) . '</h3>' .
2017-08-03 06:19:57 +00:00
'<p>' . esc_html__ ( 'You can optionally "tag" your products here. Tags are a method of labeling your products to make them easier for customers to find.' , 'woocommerce' ) . '</p>' ,
2015-04-30 12:30:03 +00:00
'position' => array (
2015-04-30 12:34:51 +00:00
'edge' => 'right' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
'product_catdiv' => array (
2018-03-05 18:59:17 +00:00
'target' => '#product_catdiv' ,
'next' => 'submitdiv' ,
2015-04-30 12:30:03 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Product categories' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__ ( 'Optionally assign categories to your products to make them easier to browse through and find in your store.' , 'woocommerce' ) . '</p>' ,
'position' => array (
2015-04-30 12:34:51 +00:00
'edge' => 'right' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
2015-04-30 12:30:03 +00:00
),
2018-03-05 18:59:17 +00:00
'submitdiv' => array (
'target' => '#submitdiv' ,
'next' => '' ,
2015-04-30 12:30:03 +00:00
'options' => array (
2016-10-12 10:16:30 +00:00
'content' => '<h3>' . esc_html__ ( 'Publish your product!' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__ ( 'When you are finished editing your product, hit the "Publish" button to publish your product to your store.' , 'woocommerce' ) . '</p>' ,
'position' => array (
2015-04-30 12:34:51 +00:00
'edge' => 'right' ,
2016-08-27 01:46:45 +00:00
'align' => 'middle' ,
),
),
),
),
2015-04-30 12:30:03 +00:00
);
$this -> enqueue_pointers ( $pointers );
}
/**
2015-07-06 09:45:10 +00:00
* Enqueue pointers and add script to page .
2018-03-05 18:59:17 +00:00
*
2015-07-06 09:45:10 +00:00
* @ param array $pointers
2015-04-30 12:30:03 +00:00
*/
public function enqueue_pointers ( $pointers ) {
2019-02-20 12:00:47 +00:00
$pointers = rawurlencode ( wp_json_encode ( $pointers ) );
2015-04-30 12:30:03 +00:00
wp_enqueue_style ( 'wp-pointer' );
wp_enqueue_script ( 'wp-pointer' );
2018-03-05 18:59:17 +00:00
wc_enqueue_js (
" jQuery( function( $ ) {
2019-02-20 12:00:47 +00:00
var wc_pointers = JSON . parse ( decodeURIComponent ( '{$pointers}' ) );
2015-04-30 12:30:03 +00:00
setTimeout ( init_wc_pointers , 800 );
function init_wc_pointers () {
2015-07-06 09:45:10 +00:00
$ . each ( wc_pointers . pointers , function ( i ) {
show_wc_pointer ( i );
return false ;
});
2015-04-30 12:30:03 +00:00
}
function show_wc_pointer ( id ) {
var pointer = wc_pointers . pointers [ id ];
var options = $ . extend ( pointer . options , {
2017-07-13 12:09:52 +00:00
pointerClass : 'wp-pointer wc-pointer' ,
2015-07-06 09:45:10 +00:00
close : function () {
if ( pointer . next ) {
show_wc_pointer ( pointer . next );
}
2017-07-13 12:09:52 +00:00
},
buttons : function ( event , t ) {
var close = '" . esc_js( __( ' Dismiss ', ' woocommerce ' ) ) . "' ,
next = '" . esc_js( __( ' Next ', ' woocommerce ' ) ) . "' ,
button = $ ( '<a class=\"close\" href=\"#\">' + close + '</a>' ),
button2 = $ ( '<a class=\"button button-primary\" href=\"#\">' + next + '</a>' ),
wrapper = $ ( '<div class=\"wc-pointer-buttons\" />' );
button . bind ( 'click.pointer' , function ( e ) {
e . preventDefault ();
t . element . pointer ( 'destroy' );
});
button2 . bind ( 'click.pointer' , function ( e ) {
e . preventDefault ();
t . element . pointer ( 'close' );
});
wrapper . append ( button );
wrapper . append ( button2 );
return wrapper ;
},
2015-07-06 09:45:10 +00:00
} );
var this_pointer = $ ( pointer . target ) . pointer ( options );
this_pointer . pointer ( 'open' );
2015-04-30 12:30:03 +00:00
2015-07-06 09:45:10 +00:00
if ( pointer . next_trigger ) {
$ ( pointer . next_trigger . target ) . on ( pointer . next_trigger . event , function () {
setTimeout ( function () { this_pointer . pointer ( 'close' ); }, 400 );
});
}
2015-04-30 12:30:03 +00:00
}
2018-03-05 18:59:17 +00:00
}); "
);
2015-04-30 12:30:03 +00:00
}
}
2015-07-06 09:45:10 +00:00
new WC_Admin_Pointers ();