Home » WooCommerce: 10 Easy Snippets to Increase Your Sales

WooCommerce: 10 Easy Snippets to Increase Your Sales

by adminkys

I had the pleasure to speak at WordCamp Prague 2019. I spoke about “10 PHP Snippets to Increase WooCommerce Sales” and managed to show some simple coding to the audience. Trust me – increasing your WooCommerce sales can also be done with a free, short, easy PHP snippet.

So, given that I want to share all the snippets I talked about, this is a quick recap. Copy them, test them (a must!) and then use them. And let me know if your conversion rate and/or AOV (average order value) increased!

At the bottom of the page you also find my talk slides. Enjoy:)

1. “Order by 6pm and get it delivered tomorrow!” notice @ Single Product Page

/**
 * @snippet       Pressure notice @ Single Product Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_single_product_summary', 'tutoraspire_display_pressure_badge', 6 );

function tutoraspire_display_pressure_badge() {
   echo '
Order by 6pm and get it delivered tomorrow!
'; }
Adding some “pressure” to the WooCommerce single product page

2. “Secure payments” image @ Checkout Page

/**
 * @snippet       “Secure payments” image @ Checkout Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_review_order_after_submit', 'tutoraspire_trust_place_order' );

function tutoraspire_trust_place_order() {
   echo '';
}
Adding a secure badge on the WooCommerce Checkout page

3. Edit “Only 1 left in stock” @ Single Product Page

/**
 * @snippet       “Only 1 left in stock” @ Single Product Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_get_availability_text', 'tutoraspire_edit_left_stock', 9999, 2 );

function tutoraspire_edit_left_stock( $text, $product ) {
   $stock = $product->get_stock_quantity();
   if ( $product->is_in_stock() && $product->managing_stock() && $stock 
Changing the scarcity message on the WooCommerce single product page

4. Distraction-free Checkout

/**
 * @snippet       Distraction-free Checkout
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'wp', 'tutoraspire_nodistraction_checkout' );

function tutoraspire_nodistraction_checkout() {
   if ( ! is_checkout() ) return;
   remove_action( 'storefront_header', 'storefront_social_icons', 10 );
   remove_action( 'storefront_header', 'storefront_secondary_navigation', 30 );
   remove_action( 'storefront_header', 'storefront_product_search', 40 );
   remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );
   remove_action( 'storefront_header', 'storefront_header_cart', 60 );
   remove_action( 'storefront_footer', 'storefront_footer_widgets', 10 );
}

5. “Try before you buy” @ Single Product Page

/**
 * @snippet       Buy a sample @ Single Product Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_single_product_summary', 'tutoraspire_add_free_sample_add_cart', 35 );

function tutoraspire_add_free_sample_add_cart() {
   echo '

Add Sample to Cart

'; }

Adding a “buy sample” button on the WooCommerce single product pge

6. Upsell @ Thank-you Page

/**
 * @snippet       Upsell @ Thank-you Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_thankyou', 'tutoraspire_thankyou_upsell', 5 );

function tutoraspire_thankyou_upsell() {
   echo '

Customers also bought...

'; echo do_shortcode( '[products limit="3" columns="3" orderby="popularity" on_sale="true"]' ); }
Showing products on sale on the WooCommerce thank you page

7. Bulk discount @ Checkout Page

/**
 * @snippet       Bulk discount @ Checkout Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_before_cart', 'tutoraspire_apply_bulk_coupon' );

function tutoraspire_apply_bulk_coupon() {
   $coupon_code = 'bulk';
   if ( WC()->cart->get_cart_contents_count() > 5 ) {
      if ( ! WC()->cart->has_discount( $coupon_code ) ) WC()->cart->add_discount( $coupon_code );
   } else {
      if ( WC()->cart->has_discount( $coupon_code ) ) WC()->cart->remove_coupon( $coupon_code );
   }
}

8. Product Add-ons @ Single Product Page

This will add a nice gift-wrap option for an extra $2.

/**
 * @snippet       Product Add-ons @ Single Product Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_before_add_to_cart_quantity', 'tutoraspire_gift_wrap', 35 );

function tutoraspire_gift_wrap() {
   ?>
   
   cart->get_cart() as $cart_item_key => $cart_item ) {
      if ( isset( $cart_item['gift-wrap'] ) ) {
         $itsagift = true;
         break;
      }
    }
    if ( $itsagift == true ) WC()->cart->add_fee( 'Gift Wrap', 2 );
}

9. BOGO

Buy One, Get One free.

/**
 * @snippet       BOGO
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_add_to_cart_validation', 'tutoraspire_bogo', 10, 3 );

function tutoraspire_bogo( $passed, $product_id, $quantity ) {
   $sku_with_gift = 'sku0001';
   $sku_free_gift = 'sku0002';
   $product = wc_get_product( $product_id );
   $sku_this = $product->get_sku();
   if ( $sku_this == $skuswithgift ) {
      WC()->cart->add_to_cart( wc_get_product_id_by_sku( $sku_free_gift ) );
   }
   return $passed;
}

10. Free Shipping Threshold @ Cart Page

Show the $ needed to reach the free shipping threshold.

/**
 * @snippet       Free Shipping Threshold @ Cart Page
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_before_cart', 'tutoraspire_free_shipping_cart_notice' );

function tutoraspire_free_shipping_cart_notice() {
   $threshold = 80;
   $current = WC()->cart->get_subtotal();
   if ( $current 

Slides

Video recording

You may also like