Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.