【发布时间】:2018-01-24 10:48:38
【问题描述】:
我正在尝试根据产品类别更改默认 Woocommerce 货币符号。
我的默认 WC 货币设置为美元,并且我的所有产品在价格前都带有 '$' 前缀。但是,我想仅针对'clearance' 类别中的产品显示'$$$',而不是'$'。
这是我的代码:
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
global $post, $product, $woocommerce;
if ( has_term( 'clearance', 'product_cat' ) ) {
switch( $currency ) {
case 'USD': $currency_symbol = '$$$'; break;
}
return $currency_symbol;
}
}
它有效,并且“$$$”仅针对“清仓”类别中的产品显示,但它会从其余类别中的所有产品中删除“$”。
如果条件不满足,我需要 if 语句不执行任何操作。
我也尝试过像这样使用endif 结束标记:
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
global $post, $product, $woocommerce;
if ( has_term( 'clearance', 'product_cat' ) ) :
switch( $currency ) {
case 'USD': $currency_symbol = '$$$'; break;
}
return $currency_symbol;
endif;
}
但这里也一样。它为“清仓”类别中的所有产品显示'$$$',但删除任何其他产品的'$'。
我做错了什么?
【问题讨论】:
标签: php wordpress if-statement woocommerce currency