Title: plugin custom logic
Last modified: August 21, 2016

---

# plugin custom logic

 *  [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/plugin-custom-logic/)
 * I have a variable that I can echo
    **global $woocommerce; var_dump($woocommerce-
   >cart->cart_contents_count);** that returns 0 if the cart is empty and an integer
   greater than 0 if it has contents.
 * In my custom plugin I put the following
 *     ```
       add_filter( 'if_menu_conditions' , 'my_cart_condition' );
       	function my_cart_condition() {
       	global $woocommerce;
       	return( $woocommerce->cart->cart_contents_count > 0 );
       	}
       ```
   
 * this empties the if drop down in the admin section of the plugin.
 * even an empty function does the same.
 *     ```
       add_filter( 'if_menu_conditions' , 'my_cart_condition' );
       	function my_cart_condition() {
       	}
       ```
   
 * What am I doing wrong?
 * Thanks for your help.
 * [http://wordpress.org/extend/plugins/if-menu/](http://wordpress.org/extend/plugins/if-menu/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/plugin-custom-logic/#post-3827614)
 * I read the readme.txt which made the formatting a little clearer and I tried 
   the following in my custom plugin
 *     ```
       add_filter( 'if_menu_conditions' , 'my_cart_condition' );
       	function my_cart_condition( $conditions ) {
       		$conditions[] = array(
       			'name'		=>	 'Cart has Contents',
       			'condition'        =>	function() {
       				global $woocommerce;
       				return( $woocommerce->cart->cart_contents_count > 0 );
       			}
       		);
       	}
       ```
   
 * this fixed the admin menu, but still doesn’t work.
    I also tried formatting like
   the code in your plugin, which also didn’t work.
 *     ```
       'name'		=>	__( 'Cart has Contents', 'if-menu' ),
       ```
   
 * I finally edited your conditions.php to add this to the conditions and THIS WORKS.
 *     ```
       $conditions[] = array(
       		'name'		=>	__( 'Cart has Contents', 'if-menu' ),
       		'condition'	=>	'if_menu_cart_has_contents'
       	);
       ```
   
 * and then this at the bottom
 *     ```
       function if_menu_cart_has_contents() {
       	global $woocommerce;
       	if( $woocommerce->cart->cart_contents_count > 0 ) return true;
       	return false;
       }
       ```
   
 * Would be much better if I could put it in my custom plugin, but i couldn’t get
   it to work with that method.
 * Thank you, hth
 *  [BramNL](https://wordpress.org/support/users/bramnl/)
 * (@bramnl)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/plugin-custom-logic/#post-3827767)
 * The key is that you guys missed the **return $conditions;**. This is a flaw in
   the FAQ.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘plugin custom logic’ is closed to new replies.

 * ![](https://ps.w.org/if-menu/assets/icon-256x256.png?rev=1862232)
 * [If Menu - Visibility control for Menus](https://wordpress.org/plugins/if-menu/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/if-menu/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/if-menu/)
 * [Active Topics](https://wordpress.org/support/plugin/if-menu/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/if-menu/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/if-menu/reviews/)

## Tags

 * [conditional menu](https://wordpress.org/support/topic-tag/conditional-menu/)

 * 2 replies
 * 2 participants
 * Last reply from: [BramNL](https://wordpress.org/support/users/bramnl/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/plugin-custom-logic/#post-3827767)
 * Status: not resolved