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

在 Woocommerce 3.2+ 中使用 Hooks 更改購物車總數

Change Cart total using Hooks in Woocommerce 3.2+(在 Woocommerce 3.2+ 中使用 Hooks 更改購物車總數)
本文介紹了在 Woocommerce 3.2+ 中使用 Hooks 更改購物車總數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想在 woocommerce 結帳頁面上為訂單總數添加 300,但 woocommerce_calculate_totals 鉤子不起作用...

I want to add 300 to order total on woocommerce checkout page but woocommerce_calculate_totals hook doesn't do the job...

如果我使用 var_dump($total),我會看到正確的結果 - int(number),但訂單表中的總金額沒有變化.

If I use var_dump($total), I see the correct result - int(number), but the total amount in order table is not changing.

add_action( 'woocommerce_calculate_totals', 'action_cart_calculate_totals', 10, 1 );

function action_cart_calculate_totals( $cart_object) {

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( !WC()->cart->is_empty() ):


        $total = $cart_object->cart_contents_total += 300;

        var_dump($total);

    endif;
}

推薦答案

從 Woocommerce 3.2 開始,鉤子 woocommerce_calculate_totals 不適用于此.
請參閱此線程的說明:在 WooCommerce 中更改購物車總價

您必須使用以下方法之一:

You will have to use one of the following ways using:

1) 過濾器鉤子 woocommerce_calculated_total 這樣:

1) The filter hook woocommerce_calculated_total this way:

add_filter( 'woocommerce_calculated_total', 'change_calculated_total', 10, 2 );
function change_calculated_total( $total, $cart ) {
    return $total + 300;
}

2) 費用 API 如下:

2) The Fee API like:

add_action( 'woocommerce_cart_calculate_fees', 'add_custom_fee', 10, 1 );
function add_custom_fee ( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $fee = 300;

    $cart->add_fee( __( 'Fee', 'woocommerce' ) , $fee, false );
}

代碼位于活動子主題(或活動主題)的 function.php 文件或任何插件文件中.

Code goes in function.php file of your active child theme (or active theme) or also in any plugin file.

這篇關于在 Woocommerce 3.2+ 中使用 Hooks 更改購物車總數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
主站蜘蛛池模板: 91传媒在线观看 | 日韩午夜一区二区三区 | 蜜桃在线一区二区三区 | 国产精品美女久久久久久久网站 | 一区在线视频 | 2019天天干天天操 | 国产精品日韩欧美一区二区三区 | 精品国产一区二区三区性色av | 大学生a级毛片免费视频 | 涩爱av一区二区三区 | 国产精品1区2区 | 日韩福利| 亚洲精品黑人 | www日韩高清 | 国产一区二 | 成人在线精品 | 91久久精品国产91久久性色tv | 91最新在线视频 | 国产成人在线观看免费 | 色婷婷一区 | 一本久久a久久精品亚洲 | 国产精品视频网站 | h网站在线观看 | 精品国产1区2区3区 在线国产视频 | 在线精品国产 | 国产美女一区二区三区 | 在线欧美亚洲 | 日韩精品a在线观看图片 | 毛片久久久 | 99国产精品久久久 | www.欧美.com| 中文在线观看视频 | 欧美日韩亚洲一区 | 成人在线免费 | 日日夜夜狠狠操 | 久久一二| 激情久久久久 | 国产日韩久久 | 国产亚洲精品一区二区三区 | 国产成人精品一区二 | 亚洲精品久久国产高清情趣图文 |