我发现以下代码可以在产品详细信息页面上显示所有自定义属性(具有我需要的特定栏样式设计)。代码的工作方式就像一个魅力,我有适当的 CSS 来显示我的自定义属性的水平条。
我的问题是我只想显示特定的命名属性,并且不知道如何更改循环来做到这一点......
function isa_woocommerce_all_pa(){
global $product;
$attributes = $product->get_attributes();
if ( ! $attributes ) {
return;
}
$out = '<ul class="taste-attributes">';
foreach ( $attributes as $attribute ) {
// skip variations
if ( $attribute->get_variation() ) {
continue;
}
$name = $attribute->get_name();
if ( $attribute->is_taxonomy() ) {
$terms = wp_get_post_terms( $product->get_id(), $name, 'all' );
// get the taxonomy
$tax = $terms[0]->taxonomy;
// get the tax object
$tax_object = get_taxonomy($tax);
// get tax label
if ( isset ( …Run Code Online (Sandbox Code Playgroud)