我已经从2.6.14更新到WC 3.0.1。
我原来的代码如下:woocommerce_before_calculate_totals在更新到WC 3.0.1后停止工作
add_action('woocommerce_before_calculate_totals', 'add_custom_price');
function add_custom_price($cart_object) {
$custom_price = 10; // This will be your custome price
foreach ($cart_object->cart_contents as $key => $value) {
$value['data']->price = $custom_price;
}
}
它不再更新的购物车或minicart的价格。
您不能再直接访问'$ product'属性。如果启用了“WP_DEBUG”,您应该在'debug.log'中看到关于此的警告。您现在必须使用setter和getters来获得产品,订单,订单商品和优惠券对象。 – helgatheviking
感谢helgatheviking, 您能否提供一个获取和设置产品价格的例子? –
查看[source]中的'set_price()'(https://github.com/woocommerce/woocommerce/blob/3.0.0/includes/abstracts/abstract-wc-product.php#L804-L806) – helgatheviking