Last active
November 27, 2017 16:50
-
-
Save webaware/2210f8a70fc4ee3bfd13eb22c3d32ebd to your computer and use it in GitHub Desktop.
Only show the Lurking Minicart when required. This code tests for WooCommerce shop, product, and product taxonomy pages (categories/tags/etc.) but you can also test for individual pages with `is_page()`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Lurking Minicart Conditional Display | |
Plugin URI: https://gist.github.com/webaware/2210f8a70fc4ee3bfd13eb22c3d32ebd | |
Description: Only show the Lurking Minicart when required | |
Author: WebAware | |
Author URI: https://lurking-minicart.webaware.net.au/ | |
*/ | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
/** | |
* only show the cart on WooCommerce shop, product, and product category/tag/etc. pages | |
* @param bool $required | |
* @param string $context can be 'edge', 'widget', 'menu', 'manual' | |
* @param string $position can be 'left', 'right', 'widget', 'menu' | |
* @return bool | |
*/ | |
add_filter('woocommerce_lurking_minicart_is_required', function($required, $context, $position) { | |
// sanity check | |
if (!function_exists('WC')) { | |
return $required; | |
} | |
if (!(is_shop() || is_product_taxonomy() || is_product())) { | |
$required = false; | |
} | |
return $required; | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment