久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

基于 WooCommerce 中購物車項目數量的附加價格

Additional price based on cart item count in WooCommerce(基于 WooCommerce 中購物車項目數量的附加價格)
本文介紹了基于 WooCommerce 中購物車項目數量的附加價格的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

基于"woocommerce 在結帳和購物車中更改價格頁面" 回答更改結帳頁面總價的代碼,我添加了一些額外的代碼來計算用戶在購物車中擁有的產品,如果用戶在購物車中有 9 個產品,則添加一些價格總計:

Based on "woocommerce change price in checkout and cart page" answer code that change the total price in checkout page, I have added some extra code to count the products that user have in cart and if user had like 9 products in cart then add some price to total:

add_action( 'woocommerce_before_cart_totals', 'custom_cart_total' , 'get_cart_contents_count');
function custom_cart_total() {

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    if (WC()->cart->get_cart_contents_count() == 9){
        WC()->cart->total += 15;
    }
    elseif(WC()->cart->get_cart_contents_count() == 6){
       WC()->cart->total += 14; 
    }
    elseif(WC()->cart->get_cart_contents_count() == 4){
       WC()->cart->total += 13; 
    }

}

但它不起作用.這張圖片將說明一切:

如果有人可以更正代碼并告訴我如何顯示圖片中的消息,我將不勝感激

I will appreciate if anyone could correct the code and tell me how can I display the message like in the picture

推薦答案

你最好改用 FEE API,這樣:

You should better use the FEE API instead, this way:

// Add a custom packing fee based on item count
add_action( 'woocommerce_cart_calculate_fees', 'custom_packing_fee', 10, 1 );
function custom_packing_fee( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( did_action( 'woocommerce_cart_calculate_fees' ) >= 2 )
        return;

    $count = $cart->get_cart_contents_count();

    if ( $count >= 9 ){
        $fee = 15;
    }
    elseif( $count >= 6 && $count < 9 ){
        $fee = 14;
    }
    elseif( $count >= 4 && $count < 6 ){
        $fee = 13;
    }

    if ( isset($fee) && $fee > 0 ) {
        $label = sprintf( __('Box fee (%d items)'), $count);
        $cart->add_fee( $label, $fee, false );
    }
}

代碼位于您的活動子主題(或活動主題)的functions.php 文件中.經測試有效.

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

如果您想為包裝費啟用稅金,請將第三個參數從 false 更改為 true.

If you want to enable taxes for the packing fee, change the third argument from false to true.

這篇關于基于 WooCommerce 中購物車項目數量的附加價格的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 亚洲精品久久久久久久久久久久久 | 欧美天堂| 久久久久久国产精品 | 夜夜摸天天操 | 九九热在线免费视频 | 日韩精品中文字幕在线 | 国产精品高潮呻吟久久av黑人 | 精品欧美一区二区三区久久久小说 | 久久久激情| av网站免费在线观看 | 亚洲一区二区三区在线 | jizz视频 | av在线免费观看网站 | 人成久久| 天天av天天好逼 | 日韩一区二区在线观看 | 激情三区 | 欧美亚洲一区二区三区 | www.亚洲精品| av一二三四 | 久久9久 | 中文字幕亚洲欧美 | 天天草av | www.国产精品| 国产人免费人成免费视频 | 老外几下就让我高潮了 | 黄免费在线 | 在线观看国产 | 亚洲精品乱码久久久久久蜜桃91 | 99精品欧美一区二区蜜桃免费 | 亚洲精品美女视频 | 久在线 | 五月婷婷激情 | 国产成人免费在线 | 男人的天堂亚洲 | 中文字幕乱码亚洲精品一区 | 九九久久国产 | 日韩视频国产 | 九九九久久国产免费 | 亚洲 中文 欧美 日韩 在线观看 | 欧美日本在线观看 |