【发布时间】:2022-01-01 10:13:36
【问题描述】:
我想仅在单个产品页面和商店存档页面上更改 WooCommerce 中某个类别的缺货消息。
我正在使用 OceanWP 主题
这是我目前所拥有的,它有效,但我需要为类别添加“if”语句。
/**
*This changes the out of stock text on the item in oceanwp theme product gallery
*/
function my_woo_outofstock_text( $text ) {
$text = __( 'Sold', 'oceanwp' );
return $text;
}
add_filter( 'ocean_woo_outofstock_text', 'my_woo_outofstock_text', 20 );
这是我的代码尝试,基于此similar question here,但它仅适用于单个产品页面。有什么建议吗?
function my_woo_outofstock_text( $text, $product ) {
$specific_categories = array( 'original-paintings' );
if ( ! $product->is_in_stock() && has_term( $specific_categories, 'product_cat', $product->get_id() ) ) {
$text = __( 'Sold', 'oceanwp' );
}
else {
$text = __( 'Unavailable', 'oceanwp' );
}
return $text;
}
add_filter( 'ocean_woo_outofstock_text', 'my_woo_outofstock_text', 20 );
【问题讨论】:
标签: wordpress woocommerce product