我不是专家,但我需要在我的 Woocommerce 产品页面中更改“out of stoke”产品的价格。
- 我找到了如何将价格更改为“已售出”(并且有效)
//Change price to 'sold'
add_filter('woocommerce_product_get_price','change_price_regular_member', woocommerce_currency_symbols, 10, 2 );
function change_price_regular_member( $price, $product)
{
if (!$product->is_in_stock())
$price = "SOLD";
return $price;
}
- 我尝试隐藏我的货币符号(将 $SOLD 更改为 SOLD)
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
global $post, $product;
if (!$product->is_in_stock() ) {
switch( $currency ) {
case 'USD': $currency_symbol = '';
break;
}}
return $currency_symbol;
}
但它不起作用
错误列表
Your PHP code changes were rolled back due to an error on line 66 of file wp-content/themes/pro-child/functions.php. Please fix and try saving again.
Uncaught Error: Call to a member function is_in_stock() on null in wp-content/themes/pro-child/functions.php:66
Stack trace:
#0 wp-includes/class-wp-hook.php(287): change_existing_currency_symbol('$', 'USD')
#1 wp-includes/plugin.php(212): WP_Hook->apply_filters('$', Array)
#2 wp-content/plugins/woocommerce/includes/wc-core-functions.php(854): apply_filters('woocommerce_cur...', '$', 'USD')
#3 wp-content/plugins/woocommerce/includes/widgets/class-wc-widget-price-filter.php(45): get_woocommerce_currency_symbol()
#4 wp-includes/class-wp-widget-factory.php(61): WC_Widget_Price_Filter->__construct()
#5 wp-includes/widgets.php(115): WP_Widget_Factory->register('WC_Widget_Price...')
#6 wp-content/plugins/woocommerce/includes/wc-
你能帮助我吗?怎么了?