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
* @ package WooCommerce / Admin
* @ 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 () {
$screen = get_current_screen ();
switch ( $screen -> id ) {
case 'product' :
$this -> create_product_tutorial ();
break ;
}
}
/**
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 (
'title' => array (
'target' => " #title " ,
'next' => 'content' ,
'next_trigger' => array (
'target' => '#title' ,
'event' => 'input'
),
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Product Name' , 'woocommerce' ) . '</h3>' .
'<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' ,
'align' => 'left'
)
)
),
'content' => array (
'target' => " #content " ,
2015-04-30 12:34:51 +00:00
'next' => 'product-type' ,
2015-04-30 12:30:03 +00:00
'next_trigger' => array (
'target' => '#content' ,
'event' => 'click change input'
),
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Product Description' , 'woocommerce' ) . '</h3>' .
'<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' ,
'align' => 'middle'
)
)
),
'product-type' => array (
'target' => " #product-type " ,
'next' => 'virtual' ,
'next_trigger' => array (
'target' => " #product-type " ,
'event' => 'change blur click'
),
'options' => array (
2015-04-30 12:34:51 +00:00
'content' => '<h3>' . esc_html__ ( 'Choose Product Type' , 'woocommerce' ) . '</h3>' .
'<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' ,
'align' => 'middle'
)
)
),
'virtual' => array (
'target' => " #_virtual " ,
'next' => 'downloadable' ,
'next_trigger' => array (
'target' => " #_virtual " ,
'event' => 'change'
),
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Virtual Products' , 'woocommerce' ) . '</h3>' .
'<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' ,
'align' => 'middle'
)
)
),
'downloadable' => array (
'target' => " #_downloadable " ,
'next' => 'regular_price' ,
'next_trigger' => array (
'target' => " #_downloadable " ,
'event' => 'change'
),
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Downloadable Products' , 'woocommerce' ) . '</h3>' .
'<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' ,
'align' => 'middle'
)
)
),
'regular_price' => array (
'target' => " #_regular_price " ,
'next' => 'postexcerpt' ,
'next_trigger' => array (
'target' => " #_regular_price " ,
'event' => 'input'
),
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Prices' , 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__ ( 'Next you\'ll need to give your product a price.' , 'woocommerce' ) . '</p>' ,
'position' => array (
'edge' => 'bottom' ,
'align' => 'middle'
)
)
),
'postexcerpt' => array (
'target' => " #postexcerpt " ,
'next' => 'postimagediv' ,
'next_trigger' => array (
'target' => " #postexcerpt " ,
'event' => 'input'
),
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Product Short Description' , 'woocommerce' ) . '</h3>' .
'<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' ,
'align' => 'middle'
)
)
),
'postimagediv' => array (
'target' => " #postimagediv " ,
'next' => 'product_tag' ,
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Product Images' , 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__ ( 'Upload or assign an image to your product here. This image will be shown in your store\'s catalog.' , 'woocommerce' ) . '</p>' ,
'position' => array (
2015-04-30 12:34:51 +00:00
'edge' => 'right' ,
2015-04-30 12:30:03 +00:00
'align' => 'middle'
)
)
),
'product_tag' => array (
'target' => " #tagsdiv-product_tag " ,
'next' => 'product_catdiv' ,
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Product Tags' , 'woocommerce' ) . '</h3>' .
2015-04-30 12:34:51 +00:00
'<p>' . esc_html__ ( 'You can optionally "tag" your products here. Tags as 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' ,
2015-04-30 12:30:03 +00:00
'align' => 'middle'
)
)
),
'product_catdiv' => array (
'target' => " #product_catdiv " ,
'next' => 'submitdiv' ,
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Product Categories' , 'woocommerce' ) . '</h3>' .
'<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' ,
2015-04-30 12:30:03 +00:00
'align' => 'middle'
)
)
),
'submitdiv' => array (
'target' => " #submitdiv " ,
'next' => '' ,
'options' => array (
'content' => '<h3>' . esc_html__ ( 'Publish Your Product!' , 'woocommerce' ) . '</h3>' .
'<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' ,
2015-04-30 12:30:03 +00:00
'align' => 'middle'
)
)
)
)
);
$this -> enqueue_pointers ( $pointers );
}
/**
2015-07-06 09:45:10 +00:00
* Enqueue pointers and add script to page .
* @ param array $pointers
2015-04-30 12:30:03 +00:00
*/
public function enqueue_pointers ( $pointers ) {
2015-08-13 11:07:12 +00:00
$pointers = json_encode ( $pointers );
2015-04-30 12:30:03 +00:00
wp_enqueue_style ( 'wp-pointer' );
wp_enqueue_script ( 'wp-pointer' );
wc_enqueue_js ( "
2015-07-06 09:45:10 +00:00
jQuery ( function ( $ ) {
2015-04-30 12:30:03 +00:00
var wc_pointers = { $pointers };
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 , {
2015-07-06 09:45:10 +00:00
close : function () {
if ( pointer . next ) {
show_wc_pointer ( pointer . next );
}
}
} );
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
}
});
" );
}
}
2015-07-06 09:45:10 +00:00
new WC_Admin_Pointers ();