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 關注
- 108 瀏覽
添加回答
舉報