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

動態購物車項目定價不適用于 WooCommerce 3.0+ 中的

Dynamic cart item pricing not working on orders in WooCommerce 3.0+(動態購物車項目定價不適用于 WooCommerce 3.0+ 中的訂單)
本文介紹了動態購物車項目定價不適用于 WooCommerce 3.0+ 中的訂單的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用的是 WooCommerce 3.0+ 并且我已經在某個頁面上設置了產品價格.

I am using WooCommerce 3.0+ and I have set the product price on a certain page.

       $regular_price = get_post_meta( $_product->id, '_regular_price', true);
      $buyback_percentage = get_post_meta( $_product->id, '_goldpricelive_buy_back', true);
      $fixed_amount = get_post_meta( $_product->id, '_goldpricelive_fixed_amount', true);
      $markedup_price = get_post_meta( $_product->id, '_goldpricelive_markup', true);
      $buyback_price = ($regular_price - $fixed_amount)/(1 + $markedup_price/100)  * (1-$buyback_percentage/100);
      $_product->set_price($buyback_price);

我的購物車上的價格正在更新,但是當我點擊提交訂單時,訂單對象似乎沒有得到我設置的價格.它需要原產地產品價格.

The price is updating on my cart but when I click on to submit my order, Order object doesn't seem to get the price I set. It takes the origin product price.

知道如何實現這一點嗎?

Any idea on how I can accomplish this?

謝謝

推薦答案

更新為 get_price() 方法……

Updated with get_price() method …

您應該在此自定義掛鉤函數、您的產品 ID 或產品 ID 數組中使用 woocommerce_before_calculate_totals 操作掛鉤設置.
然后,您可以為每個人進行自定義計算以設置將在購物車、結帳和提交訂單后設置的自定義價格.

You should use woocommerce_before_calculate_totals action hook setting inside this custom hooked function, your products IDs or an array of product IDs.
Then for each of them you can make a custom calculation to set a custom price that will be set on Cart, checkout and after submitting in the order.

這是在 WooCommerce 3.0+ 版上測試的功能代碼:

Here is that functional code tested on WooCommerce version 3.0+:

add_action( 'woocommerce_before_calculate_totals', 'adding_custom_price', 10, 1);
function adding_custom_price( $cart_obj ) {

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

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

    // Set below your targeted individual products IDs or arrays of product IDs
    $target_product_id = 53;
    $target_product_ids_arr = array(22, 56, 81);

    foreach ( $cart_obj->get_cart() as  $cart_item ) {
        // The corresponding product ID
        $product_id = $cart_item['product_id'];

        // For a single product ID
        if($product_id == $target_product_id){
            // Custom calculation
            $price = $cart_item['data']->get_price() + 50;
            $cart_item['data']->set_price( floatval($price) );
        } 

        // For an array of product IDs 
        elseif( in_array( $product_id, $target_product_ids_arr ) ){
            // Custom calculation
            $price = $cart_item['data']->get_price() + 30;
            $cart_item['data']->set_price( floatval($price) );
        }
    }
}

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

然后,您可以使用 get_post_meta() 函數輕松地將我的虛假計算中的固定值替換為您的產品動態值,就像在您的代碼中一樣,因為您擁有 $product_id對于每個購物車項目......

Then you can easily replace the fixed values in my fake calculations by your product dynamic values with that with get_post_meta() function just like in your code as you have the $product_id for each cart item…

這篇關于動態購物車項目定價不適用于 WooCommerce 3.0+ 中的訂單的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 一区免费看 | 亚洲激情综合 | 日韩在线电影 | 99亚洲精品 | 一区二区三区韩国 | 精品亚洲一区二区三区四区五区 | 九九综合| 欧美亚洲视频 | 精品一区二区视频 | 久久国产欧美日韩精品 | 国产精品久久久久久久久久久久午夜片 | 亚洲精品视频在线 | 亚洲一区二区三区在线播放 | 久久久视频在线 | 天天看天天摸天天操 | 免费激情av | 日韩精品一区二区三区在线播放 | 久久久久国产视频 | 在线观看www高清视频 | 午夜天堂精品久久久久 | 国产精品久久久久久久一区二区 | 日韩视频国产 | 成人特区| 国产一区二区三区 | 一级欧美日韩 | 成人污污视频 | 国产一级网站 | 亚洲精品成人网 | 国产精品久久久久久久久久久久 | 成人黄在线观看 | 免费一区 | 亚洲成人精品 | 三极网站 | 亚洲国产一区二区三区四区 | 在线免费观看日本 | 亚洲精品电影网在线观看 | 国产精品国产自产拍高清 | 中文成人在线 | 一级一级一级毛片 | julia中文字幕久久一区二区 | 国产精品 欧美精品 |