2016-09-07 9 views
1

私はWooCommerceで動作するプラグインを開発しており、チェックアウトページで注文を送信した直後にカスタム価格を更新する必要があります。カスタム価格wooocommerceを更新する

質問:可能ですか?

header('Location: http://myweb.com/?add-to-cart=477'); 

// define the woocommerce_review_order_after_submit callback  
function action_woocommerce_review_order_after_submit() {  

    $custom_price = 10; // This will be your custome price 
    $target_product_id = 477; 
    foreach ($cart_object->cart_contents as $value) { 
     if ($value['product_id'] == $target_product_id) { 
      $value['data']->price = $custom_price; 
     } 
    } 
} 
      
// add the action  
add_action('woocommerce_review_order_after_submit',  
'action_woocommerce_review_order_after_submit'); 

ありがとう:

私は試してみました。

+2

が重複する可能性をカスタム価格でカートに追加](http://stackoverflow.com/questions/32361369/woocommerce-add-to-cart-with-custom-price) – helgatheviking

+0

これはうまくいきましたか?それが働いたら私の答えを選んでください – Skatox

答えて

0

あなたは1の合計を計算した後上書きされますことを、別のフックでそれをしなければならない、あなたはwoocommerce_before_calculate_totalsフックにしなければならないので、add_actionコールへの変更:[Woocommerceの

add_action('woocommerce_before_calculate_totals', 'action_woocommerce_review_order_after_submit');

関連する問題