3

My task is :

I have test, test1, test2, test3 ==> 4 products

The test product price is $0.

While add to cart the price will be added to that particular 'test' product is $500

How to achieve this.

I use the following hook

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );

But it only shows the total as 500. I need to show this price as product price in my entire cart. How to do this. Please help me. Thanks

4

1 回答 1

4

我写了一个很好的指南,介绍如何向产品添加表单然后更改价格。

如果您查找我的函数“calculate_cost”并找到它使用的每个地方,您应该能够弄清楚如何修改价格以使“test”为 500 美元。

例如,您可以执行以下操作:

add_filter('woocommerce_add_cart_item', array(&$this, 'add_cart_item'), 10, 1);
function add_cart_item($cart_item) {
    // TODO: Logic to determine when this is the 'test' product
    $cart_item['data']->set_price('500');
}
于 2013-06-06T13:29:48.993 回答