6

Before asking question here I want to tell that I have already asked the question in stackoverflow and wordpress forum but have not got any answer. So finally I came here.

I have installed the woocommerce plugin in my wordpress 3.5.2. Everything is fine with woocommerce. I have made a folder called woocommerce and have pasted all the files inside the woocommerce template files inside my template folder. But there is something that I am totally stuck on. In the woocommerce checkout page I want to show cart totals in sidebar. But it is not showing there. In other pages it is working fine. So can someone kindly tell me what wrong here? Any help and suggestions will be really appreciated. Thanks

Update

Here is the screenshot for the woocommerce cart widget in sidebar which can be shown in all pages except the checkout page.

enter image description here

Edit:
Additional, how to make this change secure from updates?

3 Answers 3

6

The cart widget isn't showing because it's configured to not show on the cart and checkout page. If you want to change that take a look at class-wc-widget-cart.php, there you find the following line:

if ( is_cart() || is_checkout() ) return;  

Change it to:

if ( is_cart() ) return;  

To show the widget on the checkout page.

Note: This will be, if done in the plugins/woocommerce/classes/widgets folder, overwritten on updates.


Edit: Additional information how to override widget and make changes update secure
Source: http://www.skyverge.com/blog/overriddin-woocommerce-widgets/ (Option 5)

  1. Duplicate class-wc-widget-cart.php;
  2. Copy the duplicate into a folder inside your theme, for example: cust_woo_widgets
  3. Make above changes to the file;
  4. Additionally make the following change to the widget duplicate:

    class Custom_WooCommerce_Widget_Cart extends WooCommerce_Widget_Cart {
      function widget( $args, $instance ) {
    // copy the widget function from woocommerce/classes/widgets/class-wc-widget-cart.php
      }
    }
    
  5. Put following code into your functions.php:

    add_action( 'widgets_init', 'override_woocommerce_widgets', 15 );
    function override_woocommerce_widgets() { 
      if ( class_exists( 'WooCommerce_Widget_Cart' ) ) {
        unregister_widget( 'WooCommerce_Widget_Cart' ); 
        include_once( 'cust_woo_widgets/widget-cart.php' );
        register_widget( 'Custom_WooCommerce_Widget_Cart' );
      } 
    }
    

Note: See source for more information; untested.

2
3

I added the following code to my functions.php and now the cart is showing on all my pages.

add_filter( 'woocommerce_widget_cart_is_hidden', 'always_show_cart', 40, 0 );
function always_show_cart() {
    return false;
}
2
  • 1
    this should be the right solution, the filter got added by woocommerce - the answer from @something is outdated. you can also use the __return_false method: add_filter( 'woocommerce_widget_cart_is_hidden', '__return_false', 40, 0 );
    – cyptus
    Feb 20, 2017 at 15:53
  • Both Filter dont work anymore - any idea why?
    – NewUser
    Nov 30, 2017 at 0:03
2

It is not recommended to change the core file of the plugin as on the update your changes will be lost. Better use the following code to show cart widget in the sidebar on checkout page

add_filter('woocommerce_widget_cart_is_hidden', 'show_cart_on_checkout');

    function show_cart_on_checkout()
    {
        return is_cart();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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