【发布时间】:2020-08-23 18:09:17
【问题描述】:
基于 Allow customer to set the product price (giftcard) and add to cart if sum is minimum 100 in WooCommerce,它回答了我最初的问题 - 我还有一个关于 WooCommerce 迷你购物车的小问题。
产品价格不会根据客户使用礼品卡字段提交的内容进行相应更新。所以我有两种不同的解决方案,但都失败了。
这是我尝试过的:
add_filter('woocommerce_widget_cart_item_quantity', 'custom_wc_widget_cart_item_quantity', 10, 3 );
function custom_wc_widget_cart_item_quantity( $cart, $cart_item, $cart_item_key ) {
foreach ( $cart->get_cart() as $cart_item ) {
if ( isset ( $cart_item['giftcard_product_price'] ) ) {
$cart_item['data']->set_price( $cart_item['giftcard_product_price'] );
return sprintf( '<span class="quantity">%s × <span class="woocommerce-Price-amount amount">%s <span class="woocommerce-Price-currencySymbol">%s</span></span></span>', $cart_item['quantity'], $cart_item['giftcard_product_price'] );
}
}
}
它不起作用:Minicart 变为空白。然后我也尝试了:
add_filter('woocommerce_cart_item_price','modify_cart_product_price',10,3);
function modify_cart_product_price( $price, $cart_item, $cart_item_key){
$price = $cart_item['data']->set_price($cart_item['giftcard_product_price']);
return $price;
}
如果能得到任何帮助,我将不胜感激。
【问题讨论】:
标签: php wordpress woocommerce custom-fields minicart