woocommerce hack : free shipping incentive sales

When configuring woocommerce for wordpress shopping rates, you can opt for a combination of flat rate and free shipping with  minimum amount. by default woocommerce shopping cart will not behave perfectly. First hack will let the shopping cart shipping method selection update automatically when minimum order for free shipping is reached. Second hack will display an incentive message wehn minimum amount for free shipping is not reached. Everything is coded via filters and actions, and will work with woocommerce 2.0 and above

first hack : update shipping display choice when free shipping  minimum amount is reached

/**   from  https://github.com/woothemes/woocommerce/issues/1499
 *  Hide Standard Shipping option when free shipping is available
 */
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
function hide_standard_shipping_when_free_is_available( $available_methods ) {

    if( isset( $available_methods['free_shipping'] ) AND isset( $available_methods['flat_rate'] ) ) {

        // remove standard shipping option
        unset( $available_methods['flat_rate'] );
    }

    return $available_methods;
}

second hack : display incentive message when minimum amount is not reached, including display of minimum amount and remaining amount to add to shopping cart. Very efficient ! 

 add_action( 'woocommerce_cart_totals_after_shipping', 'webmasterbulletin_sales_incentive'  );
       function  webmasterbulletin_sales_incentive()
       {
            global $woocommerce;
            $all_methods = $woocommerce->shipping->load_shipping_methods();
           
          $available_methods = $woocommerce->shipping->get_available_shipping_methods(); 
           if (isset( $all_methods['free_shipping'] )) 
           if (isset( $available_methods['flat_rate'] ))
              echo "<tr><td colspan='2'><div class='sales_incentive'><b> 
              buy more products  :</b><br>
               only " .  woocommerce_price($all_methods['free_shipping']->settings['min_amount']-  $woocommerce->cart->cart_contents_total   ) . "  more and get <br>
              <b>free shipping starting at  
              " .    woocommerce_price($all_methods['free_shipping']->settings['min_amount']   )    . " </b>
               </div></td></tr>";
       }

 

1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *