在Woocommerce中,我使用允许用户输入他们想要支付的价格的Name your Price plugin,这应该高于设定的最低价格。
用户进行购买并付款后,我希望更改所购买产品的最低价格以匹配订单总额(用户支付的总金额)。
我在functions.php
文件中进行了以下登录,但我无法使其正常工作。
是否有遗漏或我做错了什么?
add_action( 'woocommerce_payment_complete', 'bitz_payment_complete' );
function bitz_payment_complete( $order_id ) {
$order = wc_get_order( $order_id );
$items = $order->get_items();
$ordertotalprice = $order->get_total();
//$product = wc_get_product( $product_id );
foreach ( $items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
$product_variation_id = $item->get_variation_id();
if ($item['product_id']==29) {
// Do something clever
}
}
$product = wc_get_product( $product_id );
$product_price = $product->get_price();
$sale_price = $product->get_sale_price();
//$product_minprice = $product->get_alg_wc_product_open_pricing_min_price();
$min_price = get_post_meta( $product, '_' . 'alg_wc_product_open_pricing_min_price', true );
update_post_meta($product, 'alg_wc_product_open_pricing_min_price', $ordertotalprice);
return $order_id;
return $product;
}
感谢您提供的任何帮助或帮助。
我尝试更改常规价格而不是最低价格,只是为了测试我的代码是否正常工作,但它似乎根本没有做任何事情。
答案 0 :(得分:0)
我重新访问了您的代码,并使用另一个钩子,定位“处理”和“已完成”的订单状态更改。对于“最低价格”的产品正确的元键,对于“命名您的价格”插件功能,{/ 1}}是Woocommerce中的。
_min_price
代码放在活动子主题(或主题)的function.php文件中。
经过测试和工作。