久久久久久久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)
主站蜘蛛池模板: 久久专区| 成人精品久久日伦片大全免费 | 国产视频一区二区 | 国产一区二区三区四区五区加勒比 | 国产欧美视频一区 | 欧美福利视频一区 | 精品av | 成人久久久久久久久 | 国产精品3区 | 日韩欧美国产一区二区 | 天天躁日日躁狠狠的躁天龙影院 | 久久中文字幕电影 | 亚洲精品一区二区 | 一级毛片中国 | 久久久久国产一级毛片 | 中文字幕乱码亚洲精品一区 | 99精品久久久 | 在线播放一区二区三区 | 欧美精品福利 | 国产成人精品一区二区三区在线 | 黑人巨大精品欧美黑白配亚洲 | 欧美日韩精品久久久免费观看 | 黄色毛片视频 | 欧美日韩一区二区在线观看 | 国产电影一区二区在线观看 | 97人人干 | 粉嫩av久久一区二区三区 | 人人九九 | 荷兰欧美一级毛片 | 亚洲欧美自拍偷拍视频 | 在线日韩视频 | 国产91久久久久蜜臀青青天草二 | 亚洲黄色av网站 | 国产成人一区 | 欧美乱大交xxxxx另类电影 | 在线免费视频一区 | 亚洲精品视频免费观看 | 成人深夜小视频 | 欧美视频中文字幕 | 国产日韩一区二区三区 | 国产在线视频在线观看 |