Reputation: 507
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
Upvotes: 3
Views: 7956
Reputation: 402
I wrote a nice guide on how to add a form to a product and then change the price.
If you look for my function 'calculate_cost' and find every where it is used, you should be able to figure out how to modify the price such that 'test' is $500.
For example you could do something like this:
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');
}
Upvotes: 4