我使用以下命令行从相关的WooCommerce产品中排除特定标签产品:
add_filter( 'woocommerce_get_related_product_tag_terms', 'remove_related_tags' );
function remove_related_tags( $terms ) {
foreach ( $terms as $key => $term ) {
if ( 'Đồng Hồ Thụy Sỹ' === $term->name ) {
unset( $terms[ $key ] );
}
if ( 'dong-ho-thuy-sy' === $term->slug ) {
unset( $terms[ $key ] );
}
if ( 'Đồng Hồ 6 Kim' === $term->name ) {
unset( $terms[ $key ] );
}
if ( 'Citizen Eco-Drive' === $term->name ) {
unset( $terms[ $key ] );
}
if ( 'Seiko Kinetic' === $term->name ) {
unset( $terms[ $key ] );
}
if ( 'Seiko Solar' === $term->name ) {
unset( $terms[ $key ] );
}
if ( 'Đồng Hồ Dây Da Nam Nữ' === $term->name ) {
unset( $terms[ $key ] );
}
}
return $terms;
}
但是,自从WooCommerce更新版本3后,此代码不再起作用并且无效 .
有没有其他方法可以从相关产品中排除特定标签产品?
1 回答
自从woocommerce 3以来,到处都有变化 . 现在,在那个钩子中,不再有产品标签术语对象的数组,而只是一个术语ID的数组...这就是你的代码无法工作的原因 .
应该用以下方法替换它:
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .