- This topic has 2 replies, 2 voices, and was last updated 9 years, 9 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
Support site for Tips and Tricks HQ premium products
by
Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › WP eStore General Questions › Need menu item only if cart has item(s)
Tagged: menu item
Hi,
I have a WordPress plugin that allows me to add conditional filters to any menu item. I just need to know what filter I could add to it that would indicate the cart has items in it or is empty.
Plugin author’s example of adding a new conditional statement for displaying/hiding a menu item when current page is a custom-post-type:
// theme's functions.php or plugin file
add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
function my_new_menu_conditions( $conditions ) {
$conditions[] = array(
'name' => 'If single custom-post-type', // name of the condition
'condition' => function($item) { // callback - must return TRUE or FALSE
return is_singular( 'my-custom-post-type' );
}
);
return $conditions;
}
How could that code be modified to display/hide a menu item when the cart has items and hide it when it is empty?
Thanks much!
You can use the eStore_get_total_cart_item_qty() PHP function to return the number of items in the cart. If the return value is > 0 it means there are items in the cart.
Thanks! I was able to make it work with that tidbit of information