1 回答
TA贡献1946条经验 获得超3个赞
您的问题代码自 WooCommerce 3 起已过时且已弃用......而是使用以下应与您的场景相匹配的代码:
add_filter( 'woocommerce_product_get_price', 'custom_discount_price', 10, 2 );
add_filter( 'woocommerce_product_variation_get_price', 'custom_discount_price', 10, 2 );
function custom_discount_price( $price, $product ) {
// For logged in users
if ( is_user_logged_in() ) {
$discount_rate = 0.9; // 10% of discount
// Product is on sale
if ( $product->is_on_sale() ) {
// return the smallest price value between on sale price and custom discounted price
return min( $price, ( $product->get_regular_price() * $discount_rate ) );
}
// Product is not on sale
else {
// Returns the custom discounted price
return $price * $discount_rate;
}
}
return $price;
}
代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。
- 1 回答
- 0 关注
- 84 浏览
添加回答
举报