WooCommerce:增加銷售額的 10 個簡單片段

已發表: 2019-02-22

我很高興在 2019 年布拉格 WordCamp 上發表演講。我談到了“10 個 PHP Snippets to increase WooCommerce Sales”,並設法向觀眾展示了一些簡單的編碼。 相信我——增加你的 WooCommerce 銷售額也可以通過一個免費、簡短、簡單的 PHP 片段來完成

所以,鑑於我想分享我談到的所有片段,這是一個快速回顧。 複製它們,測試它們(必須!),然後使用它們。 如果您的轉化率和/或 AOV(平均訂單價值)增加,請告訴我!

在頁面底部,您還可以找到我的演講幻燈片。 享受:)

1.“下午6點前下單,明天發貨!” 通知@單品專頁

/**
 * @snippet       Pressure notice @ Single Product Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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

function bbloomer_display_pressure_badge() {
   echo '<div class="woocommerce-message">Order by 6pm and get it delivered tomorrow!</div>';
}
給 WooCommerce 單品頁面增加一些“壓力”

2.“安全支付”圖片@結帳頁面

/**
 * @snippet       “Secure payments” image @ Checkout Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_review_order_after_submit', 'bbloomer_trust_place_order' );

function bbloomer_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">';
}
在 WooCommerce 結帳頁面上添加安全徽章

3. 編輯“僅存1件”@單品頁面

/**
 * @snippet       “Only 1 left in stock” @ Single Product Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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

function bbloomer_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;
}
更改 WooCommerce 單品頁面上的稀缺信息

4.無干擾結帳

/**
 * @snippet       Distraction-free Checkout
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'wp', 'bbloomer_nodistraction_checkout' );

function bbloomer_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.“先試后買”@單品專頁

/**
 * @snippet       Buy a sample @ Single Product Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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

function bbloomer_add_free_sample_add_cart() {
   echo '<p><a href="/?add-to-cart=953" class="button">Add Sample to Cart</a><p>';
}
在 WooCommerce 單品頁面上添加“購買樣品”按鈕

6. 追加銷售@感謝頁面

/**
 * @snippet       Upsell @ Thank-you Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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

function bbloomer_thankyou_upsell() {
   echo '<h2>Customers also bought...</h2>';
   echo do_shortcode( '[products limit="3" columns="3" orderby="popularity" on_sale="true"]' );
}
在 WooCommerce 感謝頁面上顯示正在銷售的產品

7. 批量折扣@結帳頁面

/**
 * @snippet       Bulk discount @ Checkout Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_before_cart', 'bbloomer_apply_bulk_coupon' );

function bbloomer_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. 產品附加組件@單個產品頁面

這將為額外的 2 美元添加一個不錯的禮品包裝選項。

/**
 * @snippet       Product Add-ons @ Single Product Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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

function bbloomer_gift_wrap() {
   ?>
   <label><input type="checkbox" name="gift-wrap" value="Yes">$2 Gift Wrap?</label>
   <?php
}

add_filter( 'woocommerce_add_cart_item_data', 'bbloomer_store_gift', 10, 2 );

function bbloomer_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', 'bbloomer_add_checkout_fee' );

function bbloomer_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

買一贈一。

/**
 * @snippet       BOGO
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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

function bbloomer_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. 免費送貨門檻@購物車頁面

顯示達到免費送貨門檻所需的美元。

/**
 * @snippet       Free Shipping Threshold @ Cart Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_before_cart', 'bbloomer_free_shipping_cart_notice' );

function bbloomer_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' );
   }
}

幻燈片

視頻錄製