Widget Logic
[resolved] IF logic with Widget Logic (4 posts)

  1. jimlongo
    Posted 3 years ago #

    I'm sorry it seems like this should be straightforward, but I don't see any mention of how to use IF logic in 'Widget Logic'

    How do I do the following?
    global woocommerce; return ( if ( $woocommerce->cart->cart_contents_count!==0 ) );


  2. alanft
    Plugin Author

    Posted 3 years ago #

    just leave out the "if" and

    global $woocommerce; return ( $woocommerce->cart->cart_contents_count!==0 );

    or "==0" depending on how you want it to work. So long as your Widget Logic code returns true, the widget will appear. Two notes:

    1) i added a $ in the global
    2) i'm not entirely sure you can do $object->propertyX->propertyY directly.

  3. jimlongo
    Posted 3 years ago #

    Thanks alanft.

    If I echo
    global $woocommerce; var_dump ( $woocommerce->cart->cart_contents_count);

    it returns int(1) or more when there is something in the cart and int(0) when the cart is empty.

    However the statement you gave me always shows the menu, whether the cart has contents or not. I've tried >0 as well.

  4. jimlongo
    Posted 3 years ago #

    I must apologize, I just remembered that the only reason I asked this question was to understand "Widget Logic" , and I believe you have explained it to me. I'm not using your plugin at the moment.

    I'm actually using this logic in another plugin that claims It works like 'Widget Logic' but for menu items..

    Now that I understand the logic expression I'll go bother that author.

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic