Ние създаваме уебсайтове за теб и твоят бизнес. За информация и запитвания: +359 876 700 417

12.06.2017

Create a message for remaining amount of a purchase for free delivery in WooCommerce

Every online store owner aims at making things easier for his clients. This naturally leads to the second aim – developing the need and willingness within the costumer’s mind to shop even more from the store.

There is a very easy but effective psychological trick that makes your customers increase the amount spent in your online store. It is called – amount to FREE delivery.

Experiments point at the fact that customers prefer to pay bigger price for a product than spending money on shipping. Marketers use this trick to gain more trust by removing the shipping cost for purchase over fixed amount.

Most clients would be willing to buy something extra from your store than paying for delivery. How to prompt them to do that? Well read on, my friend!

With this short article we will be showing you how to make your clients add enough products in their cart in order to reach the minimum prize for free delivery. With the message that we are going to design we will create the need within them to add products that they probably didn’t intend to purchase at first. Sounds great, right?

Let’s get to business!

It sounds more complex than it is. But in a few seconds you will be surprised to find out how easy this process is. Just follow our lead.

What you need to do is to add the following code to functions.php file of your theme or child theme.

// Notice with $$$ remaining to Free Shipping @ WooCommerce Cart 
// Tested with WooCommerce version 3.0.5 

function free_shipping_cart_notice() { 
  global $woocommerce; 

  // Get Free Shipping Methods for Rest of the World Zone & populate array $min_amounts
  $default_zone = new WC_Shipping_Zone(0); 
  $default_methods = $default_zone->get_shipping_methods();

    foreach( $default_methods as $key => $value ) {
      if ( $value->id === "free_shipping" ) {
        if ( $value->min_amount > 0 ) $min_amounts[] = $value->min_amount;
      }
    }

    // Get Free Shipping Methods for all other ZONES & populate array $min_amounts
    $delivery_zones = WC_Shipping_Zones::get_zones();

    foreach ( $delivery_zones as $key => $delivery_zone ) {
      foreach ( $delivery_zone['shipping_methods'] as $key => $value ) {
        if ( $value->id === "free_shipping" ) {
          if ( $value->min_amount > 0 ) $min_amounts[] = $value->min_amount;
        }
      }
    }

    // Find lowest min_amount
    if ( is_array($min_amounts) ) {
       $min_amount = min($min_amounts);

       // Get Cart Subtotal inc. Tax excl. Shipping
       $current = WC()->cart->subtotal;

       // If Subtotal < Min Amount, еcho Notice and add "Continue Shopping" button
       if ( $current < $min_amount ) {
          $added_text = esc_html__('You need to add ', 'woocommerce' ) . wc_price( $min_amount - $current ) . esc_html__(' for free delivery!', 'woocommerce' );
    $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( '/' ) );
    $notice = sprintf( '%s %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'woocommerce' ), $added_text );
    wc_print_notice( $notice, 'notice' );
       }
    }
}
add_action( 'woocommerce_before_cart', 'free_shipping_cart_notice' );

And… Congrats! You already have another cool functionality which will make your clients shop more than ever.

If you have any questions regarding the presented content or you need any help, please comment below or contact us.

We will be happy to assist you!

English ,
Контакти
гр. София
+359 876 700 417
Cart