in-product discovery - show items if companion extension(s) installed

This commit is contained in:
haszari 2019-02-13 11:33:37 +13:00
parent 8b22f4b040
commit 8151f28c79
1 changed files with 25 additions and 0 deletions

View File

@ -14,12 +14,26 @@
{
slug: 'products-empty-memberships',
context: 'products-list-empty-body',
'show-if-installed': [ 'woocommerce-subscriptions' ],
content: '<div class="card">' +
'<h2>Memberships</h2>' +
'<p>Give members access to restricted content or products</p>' +
'<a class="button" href="https://woocommerce.com/products/woocommerce-memberships/">From $149</a>' +
'</div>'
},
{
slug: 'products-empty-addons',
context: 'products-list-empty-body',
'show-if-installed': [
'woocommerce-subscriptions',
'woocommerce-memberships',
],
content: '<div class="card">' +
'<h2>Product Add-Ons</h2>' +
'<p>Offer add-ons like gift wrapping, special messages or other special options for your products.</p>' +
'<a class="button" href="https://woocommerce.com/products/product-add-ons/">From $149</a>' +
'</div>'
},
{
slug: 'products-empty-product-bundles',
context: 'products-list-empty-body',
@ -62,6 +76,17 @@
// hide promos for things the user already has installed
promos = _.filter( promos, ( promo ) => ! _.contains( installed_woo_plugins, promo['hide-if-installed'] ) );
// hide promos that are not applicable based on user's installed extensions
promos = _.filter( promos, ( promo ) => {
if ( ! promo['show-if-installed'] ) {
// this promotion is relevant to all
return true;
}
// if the user has any of the prerequisites, show the promo
return ( _.intersection( installed_woo_plugins, promo['show-if-installed'] ).length > 0 );
} );
return promos;
}