woocommerce 在添加到购物车时添加动态价格 [英] woocommerce add dynamic price while add to cart
问题描述
我的任务是:
我有 test、test1、test2、test3 ==> 4 个产品
I have test, test1, test2, test3 ==> 4 products
测试产品价格为 0 美元.
The test product price is $0.
当添加到购物车时,该特定测试"产品的价格将是 500 美元
While add to cart the price will be added to that particular 'test' product is $500
如何实现这一目标.
我使用以下钩子
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
但它只显示总数为 500.我需要在我的整个购物车中将此价格显示为产品价格.这该怎么做.请帮我.谢谢
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
推荐答案
我写了一个 很好的指南,了解如何向产品添加表单然后更改价格.
I wrote a nice guide on how to add a form to a product and then change the price.
如果您查找我的函数 'calculate_cost' 并找到使用它的所有地方,您应该能够弄清楚如何修改价格,使 'test' 为 500 美元.
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');
}
这篇关于woocommerce 在添加到购物车时添加动态价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!