Add onboarding load sample products notice
This commit is contained in:
parent
570d6dad71
commit
5476f4c80f
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { dispatch } from '@wordpress/data';
|
||||
import domReady from '@wordpress/dom-ready';
|
||||
import { getAdminLink } from '@woocommerce/settings';
|
||||
|
||||
domReady( () => {
|
||||
dispatch( 'core/notices' ).createSuccessNotice(
|
||||
__( 'Sample products added' ),
|
||||
{
|
||||
id: 'WOOCOMMERCE_ONBOARDING_LOAD_SAMPLE_PRODUCTS_NOTICE',
|
||||
actions: [
|
||||
{
|
||||
url: getAdminLink( 'admin.php?page=wc-admin' ),
|
||||
label: __(
|
||||
'Continue setting up your store',
|
||||
'woocommerce'
|
||||
),
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
} );
|
|
@ -48,6 +48,7 @@ const wpAdminScripts = [
|
|||
'print-shipping-label-banner',
|
||||
'beta-features-tracking-modal',
|
||||
'payment-method-promotions',
|
||||
'onboarding-load-sample-products-notice',
|
||||
];
|
||||
const getEntryPoints = () => {
|
||||
const entryPoints = {
|
||||
|
|
|
@ -19,6 +19,7 @@ class Products extends Task {
|
|||
parent::__construct( $task_list );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'possibly_add_manual_return_notice_script' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'possibly_add_import_return_notice_script' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'possibly_add_load_sample_return_notice_script' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,6 +152,43 @@ class Products extends Task {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a return to task list notice when completing the loading sample products action.
|
||||
*
|
||||
* @param string $hook Page hook.
|
||||
*/
|
||||
public function possibly_add_load_sample_return_notice_script( $hook ) {
|
||||
global $post;
|
||||
if ( 'edit.php' !== $hook || 'product' !== $post->post_type ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$referer = wp_get_referer();
|
||||
if ( ! $referer || 0 !== strpos( $referer, wc_admin_url() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isset( $_GET[ Task::ACTIVE_TASK_TRANSIENT ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$task_id = sanitize_title_with_dashes( wp_unslash( $_GET[ Task::ACTIVE_TASK_TRANSIENT ] ) );
|
||||
if ( $task_id !== $this->get_id() || ! $this->is_complete() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$script_assets_filename = WCAdminAssets::get_script_asset_filename( 'wp-admin-scripts', 'onboarding-product-notice' );
|
||||
$script_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . 'wp-admin-scripts/' . $script_assets_filename;
|
||||
|
||||
wp_enqueue_script(
|
||||
'onboarding-load-sample-products-notice',
|
||||
WCAdminAssets::get_url( 'wp-admin-scripts/onboarding-load-sample-products-notice', 'js' ),
|
||||
array_merge( array( WC_ADMIN_APP ), $script_assets ['dependencies'] ),
|
||||
WC_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the store has any published products.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue