3 Good code for WooCommerce Store

  1. Clear cart: Sometimes we want to add clear cart button on checkout or any other step in that case below code is helpful. In this we just need to pass a parameter in URL. Here you can set any url depends on you. You can redirect the customer on Home page or any other page too.

Please pass action parameter with clear value to execute the below code. Paste this code in functions.php of theme.

add_action( ‘init’, ‘woocommerce_clear_cart_url’ );

function woocommerce_clear_cart_url() {

  global $woocommerce;

   if (isset( $_GET[‘action’] ) ) {

          if ($_GET[‘action’] ==’clear’ )  {

          $woocommerce->cart->empty_cart();

                   }

    }

}

  • Disable Zoom effect on single product page:

WooCommerce have own code to zoom image on mouseover. If want to disable that then use below code in functions. php

add_filter( ‘woocommerce_single_product_zoom_enabled’, ‘__return_false’ );

  • Disable the Shipping option from checkout

WooCommerce has 2 addresses. First one is Billing address and Second is Shipping Address. Few websites uses same address for Billing and Shipping as they do not deliver any physical good. So below code is helpful for those users. Paste below code in functions.php to disable the shipping address from checkout of woocommerce.

add_filter( ‘woocommerce_cart_needs_shipping_address’, ‘__return_false’);