Skip to content

Instantly share code, notes, and snippets.

@webaware
Last active November 27, 2017 16:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webaware/2210f8a70fc4ee3bfd13eb22c3d32ebd to your computer and use it in GitHub Desktop.
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()`
<?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