我已经创建了一堆短代码,它们要么在帖子中使用,要么使用wordpress钩子回放到产品页面中。
我正在尝试创建一个条件函数,以便它根据产品类别回显特定的短码。它需要回显到'woocommerce_after_single_product_summary‘中。
这是到目前为止的草稿,有人能给出一些建议如何完成这一点吗?
add_action( 'woocommerce_after_single_product_summary', 'add_warranty_notice', 15 );
function add_warranty_notice() {
if ( is_product_category( 'xx-slug' ) ) {
echo do_shortcode("[xx-product-notice]");
} elseif ( is_product_category( 'xy-slug' ) ) {
echo do_shortcode("[xy-product-notice]");
}
}发布于 2020-02-28 20:18:29
希望这能对你有所帮助。
add_action( 'woocommerce_after_single_product_summary', 'add_warranty_notice', 15 );
function add_warranty_notice() {
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
$nterms = get_the_terms( $post->ID, 'product_tag' );
foreach ($terms as $term ) {
$product_cat_id = $term->term_id;
$product_cat_name = $term->name;
break;
}
if ( $product_cat_name == 'parent_one' ) {
echo do_shortcode("[xx-product-notice]");
} elseif ( $product_cat_name == 'parent_two' ) {
echo do_shortcode("[xy-product-notice]");
}else{
}
}https://stackoverflow.com/questions/60448902
复制相似问题