2016-07-25 124 views
0

大家好我已根據我的要求定製了woo-commerce單品頁面,所以現在兩個價格都是第一個價格是我的自定義價格,根據我的選擇,第二個價格我輸入了從WooCommerce產品頁面(從wp-admin儀表板輸入),現在第二個價格是在購物車中,但我想通過自定義價格,我怎麼能實現這一點,請提前告訴我,謝謝你。WooCommerce-發送自定義選定的價格購物車

Using ajax I am changing my custom price 
Custom Price: 
<p class="prices" id="demo" style="margin-left:22%;"></p> 

Default Price: 
<p class="prices" id="demo" style="margin-left:22%;"><?php echo $product->get_price_html(); ?></p> 

更新: 我使用這個代碼

add_action('woocommerce_before_calculate_totals', 'add_custom_price'); 
function add_custom_price($cart_object) { 


    $custom_price = 70; // This will be your custome price 
    foreach ($cart_object->cart_contents as $key => $value) { 
     $value['data']->price = $custom_price; 
    } 

}

現在70是不是這個我想通過一段因爲我用得到我的價格在一段靜態市盈率ajax ..

<p class="prices" id="demo" style="margin-left:22%;"></p> 

woocommerce custom selected price

回答

0
add_action('woocommerce_get_price','change_price_custom', 10, 2); 
function change_price_custom($price, $productd){ 
    return $price*2; // do calculation here 
} 

在主題的function.php試試這個

+0

感謝答覆..let我嘗試 –

+0

您的函數計算默認價格,我想通過Ajax傳遞自定義價格的車,我使用AJAX進行計算我我正在調用PHP文件,我已經寫了查詢我怎麼能​​這樣做,請建議... –

+0

請檢查我的段落中更新的代碼我現在得到我的價格我想通過段落,但它不工作幫助我的人.. –

相關問題