如何解决显示为 WooCommerce 产品设置的特定产品属性链接术语
例如,一个产品的属性 pa_color
有 3 个值(“silver”、“red”和“brown”)。
我想显示三个指向其描述的动态链接。
我想向我的产品展示此文字:
“此产品有这三种颜色:银色(html 链接)、红色(html 链接)、棕色(html 链接)”
如果它有一个属性,我设法做到了:
if ( is_product() && has_term( 'Silver','pa_color' ) ) {
}
解决方法
使用以下代码显示为产品设置的属性喜欢颜色:
$taxonomy = 'pa_color'; // Here set the product attribute taxonomy
$terms = wp_get_post_terms( get_the_ID(),$taxonomy ); // Get the terms
if ( ! empty( $terms ) ) {
$output = []; // Initializing
// Loop through the terms set in the product
foreach( $terms as $term ) {
$output[] = '<a href="'.get_term_link( $term,$taxonomy ).'">'.$term->name.'</a>';
}
// Display
printf( __("This product has these %s %s: %s."),count($terms),_n( "color","colors",count($terms) ),implode( ',',$output ) );
}
经过测试并有效。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。