Every e-commerce store owner aims to increase the sales. Moreover, website experience is one prime thing that is responsible to drive your sales. Also, the UX has potential to either improve or downgrade your total sales volumes. So, in this article, you will learn about PHP Snippets to Increase sales. You can implement these coding techniques in your WooCommerce platform.
Furthermore, learn these snippets, copy & apply them. In the end, let me know if these techniques worked for you or not.
1. Create Alert ‘Order by 6 pm & get it delivered tomorrow’ at Single Product page
add_action( 'woocommerce_single_product_summary', 'phpsof_display_pressure_badge', 6 );
function phpsof_display_pressure_badge() {
echo '<div class="woocommerce-message">Order by 6pm and get it delivered tomorrow!</div>';
}
2. Display ‘Secure Payment’ image at checkout page
add_action( 'woocommerce_review_order_after_submit', 'phpsof_trust_place_order' );
function phpsof_trust_place_order() {
echo '<img src="https://www.paypalobjects.com/digitalassets/c/website/marketing/na/us/logo-center/9_bdg_secured_by_pp_2line.png" style="margin: 1em auto">';
}
3. Showcase ‘Only 1 left in Stock’ at Single Product page
So, this is next PHP Snippets to Increase sales.
add_filter( 'woocommerce_get_availability_text', 'phpsof_edit_left_stock', 9999, 2 );
function phpsof_edit_left_stock( $text, $product ) {
$stock = $product->get_stock_quantity();
if ( $product->is_in_stock() && $product->managing_stock() && $stock <= get_option( 'woocommerce_notify_low_stock_amount' ) ) $text .= '. Get it today to avoid 5+ days restocking delay!';
return $text;
}
4. Enable Distraction-free Customer Checkout
add_action( 'wp', 'phpsof_nodistraction_checkout' );
function phpsof_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’ at Product page
add_action( 'woocommerce_single_product_summary', 'phpsof_add_free_sample_add_cart', 35 );
function phpsof_add_free_sample_add_cart() {
echo '<p><a href="/?add-to-cart=953" class="button">Add Sample to Cart</a></p>';
}
6. Upsell another products at Thank-You page
add_action( 'woocommerce_thankyou', 'phpsof_thankyou_upsell', 5 );
function phpsof_thankyou_upsell() {
echo '<h2>Customers also bought...</h2>';
echo do_shortcode( '' );
}
7. Enable Bulk Discount function at Checkout page
add_action( 'woocommerce_before_cart', 'phpsof_apply_bulk_coupon' );
function phpsof_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. Enable Product Add-ons at Product page
add_action( 'woocommerce_before_add_to_cart_quantity', 'phpsof_gift_wrap', 35 );
function phpsof_gift_wrap() {
?>
<label><input type="checkbox" name="gift-wrap" value="Yes">$2 Gift Wrap?</label>
<?php
}
add_filter( 'woocommerce_add_cart_item_data', 'phpsof_store_gift', 10, 2 );
function phpsof_store_gift( $cart_item, $product_id ) {
if( isset( $_POST['gift-wrap'] ) ) $cart_item['gift-wrap'] = $_POST['gift-wrap'];
return $cart_item;
}
add_action( 'woocommerce_cart_calculate_fees', 'phpsof_add_checkout_fee' );
function phpsof_add_checkout_fee() {
foreach ( WC()->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
Furthermore, it is another PHP Snippets to Increase sales. So, you must use it to generate good sales volumes.
add_filter( 'woocommerce_add_to_cart_validation', 'phpsof_bogo', 10, 3 );
function phpsof_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. Implement Free Shipping Threshold at Cart page
add_action( 'woocommerce_before_cart', 'phpsof_free_shipping_cart_notice' );
function phpsof_free_shipping_cart_notice() {
$threshold = 80;
$current = WC()->cart->get_subtotal();
if ( $current < $threshold ) {
wc_print_notice( 'Get free shipping if you order ' . wc_price( $threshold - $current ) . ' more!', 'notice' );
}
}
Where do you add this snippet?
In conclusion, implement these PHP Snippets to Increase sales. So, you can add this PHP snippet at your child theme function.php file’s bottom. Also, it should be placed before “?>”, if you have it there. Moreover, CSS goes in your child theme style.css file.
Is this snippet still valid?
So, it will increase your business sales as your website user experience is improved. Nonetheless, hope you find these snippets easier to implement. Also, I have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. So, let me know if everything works as expected. Nevertheless, share it further if this snippet has saved your time.
Also Read, How to Implement WooCommerce Quantity based Pricing Without a Plugin
A Complete Tutorial for WooCommerce Show SKU @ Cart Page
Important links: WooCommerce – https://woocommerce.com/