WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using woocommerce plugin in my WordPress setup. I want the Checkout in the menu bar should appear only when there is something in the cart. How can I do this?

share|improve this question
what is the question? – Mark Kaplun Oct 31 '13 at 7:07
If I understand correctly, the OP would like to show a Checkout menu item when there is something in the cart. @Rekha Haridoss could you confirm? The question and especially title should be edited if that is the case. – helgatheviking Nov 1 '13 at 20:56

You can adjust what items are shown in the menu via the wp_get_nav_menu_items. This is the same filter that I am using in my Nav Menu Roles plugin. Adapting from that, we can loop through the menu items, and check if any of them are links to the "checkout" page. From there we can test if the cart is empty. If both are true, then we remove the item from the menu.

function wpa_120740_exclude_menu_items( $items ){  //var_dump( $items );
    global $woocommerce;

    if( is_admin() || ! function_exists( 'woocommerce_get_page_id' ) ) return $items;

      // Iterate over the items to search and destroy
      foreach ( $items as $key => $item ) {  

          if( $item->object_id == woocommerce_get_page_id( 'checkout' ) ){
            $cart_contents = $woocommerce->cart->get_cart();
            if( empty ( $cart_contents ) ){
                 unset( $items[$key] ) ;
    return $items;
add_filter( 'wp_get_nav_menu_items', 'wpa_120740_exclude_menu_items' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.