snooze suggestions in product list (for 24 hours) after a suggestion is dismissed
This commit is contained in:
parent
6caaf80fa6
commit
1ed027bb09
|
@ -1,4 +1,4 @@
|
|||
/* global marketplace_suggestions, ajaxurl */
|
||||
/* global marketplace_suggestions, ajaxurl, Cookies */
|
||||
( function( $, marketplace_suggestions, ajaxurl ) {
|
||||
$( function() {
|
||||
if ( 'undefined' === typeof marketplace_suggestions ) {
|
||||
|
@ -17,7 +17,7 @@
|
|||
// All have one property for `suggestionSlug`, to identify the specific suggestion message.
|
||||
|
||||
// Dismiss the specified suggestion from the UI, and save the dismissal in settings.
|
||||
function dismissSuggestion( suggestionSlug ) {
|
||||
function dismissSuggestion( context, suggestionSlug ) {
|
||||
// hide the suggestion in the UI
|
||||
var selector = '[data-suggestion-slug=' + suggestionSlug + ']';
|
||||
$( selector ).fadeOut( function() {
|
||||
|
@ -35,13 +35,19 @@
|
|||
}
|
||||
);
|
||||
|
||||
// if this is a high-use area, delay new suggestion that area for a short while
|
||||
const highUseSuggestionContexts = [ 'products-list-inline' ];
|
||||
if ( _.contains( highUseSuggestionContexts, context ) ) {
|
||||
Cookies.set( 'woocommerce_snooze_products_list_suggestions', '1', { expires: 1 } );
|
||||
}
|
||||
|
||||
window.wcTracks.recordEvent( 'marketplace_suggestion_dismissed', {
|
||||
suggestionSlug: suggestionSlug
|
||||
} );
|
||||
}
|
||||
|
||||
// Render DOM element for suggestion dismiss button.
|
||||
function renderDismissButton( suggestionSlug ) {
|
||||
function renderDismissButton( context, suggestionSlug ) {
|
||||
var dismissButton = document.createElement( 'a' );
|
||||
|
||||
dismissButton.classList.add( 'suggestion-dismiss' );
|
||||
|
@ -49,7 +55,7 @@
|
|||
dismissButton.setAttribute( 'href', '#' );
|
||||
dismissButton.onclick = function( event ) {
|
||||
event.preventDefault();
|
||||
dismissSuggestion( suggestionSlug );
|
||||
dismissSuggestion( context, suggestionSlug );
|
||||
};
|
||||
|
||||
return dismissButton;
|
||||
|
@ -167,7 +173,7 @@
|
|||
}
|
||||
|
||||
if ( allowDismiss ) {
|
||||
container.appendChild( renderDismissButton( slug ) );
|
||||
container.appendChild( renderDismissButton( context, slug ) );
|
||||
}
|
||||
|
||||
return container;
|
||||
|
@ -356,6 +362,11 @@
|
|||
$( '.wp-admin.admin-bar.edit-php.post-type-product table.wp-list-table.posts tbody').first().each( function() {
|
||||
var context = 'products-list-inline';
|
||||
|
||||
// product list banner suggestion is temporarily suppressed after a recent dismissal
|
||||
if ( Cookies.get( 'woocommerce_snooze_products_list_suggestions' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// find promotions that target this context
|
||||
var promos = getRelevantPromotions( marketplaceSuggestionsApiData, context );
|
||||
if ( ! promos || ! promos.length ) {
|
||||
|
|
|
@ -114,6 +114,8 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
|
|||
wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' );
|
||||
wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.4' );
|
||||
wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION );
|
||||
wp_register_script( 'js-cookie', WC()->plugin_url() . '/assets/js/js-cookie/js.cookie' . $suffix . '.js', array(), '2.1.4', true );
|
||||
|
||||
wp_localize_script(
|
||||
'wc-enhanced-select',
|
||||
'wc_enhanced_select_params',
|
||||
|
@ -428,7 +430,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
|
|||
wp_register_script(
|
||||
'marketplace-suggestions',
|
||||
WC()->plugin_url() . '/assets/js/admin/marketplace-suggestions' . $suffix . '.js',
|
||||
array( 'jquery', 'underscore' ),
|
||||
array( 'jquery', 'underscore', 'js-cookie' ),
|
||||
WC_VERSION,
|
||||
true
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue