我想在woocommerce中获得特定的自定义属性.
我已经在这个网站上阅读了大量的线程,提供了大约3-5种方法.
在尝试了所有之后,对我有用的唯一方法是遍历所有属性 – 所有其他属性都不起作用.
我有一个名为’pdfs’的自定义属性
以下尝试不起作用:(link)
$global product;
$myPdf = array_shift( wc_get_product_terms( $product->id, 'pdfs', array( 'fields' => 'names' ) ) );
$myPdf = $product->get_attribute( 'pdfs' );
$myPdf = get_post_meta($product->id, 'pdfs', true);
这是唯一有效的方法:(link)
$attributes = $product->get_attributes();
foreach ( $attributes as $attribute ) {
if (attribute_label( $attribute[ 'name' ] ) == "pdfs" ) {
echo array_shift( wc_get_product_terms( $product->id, $attribute[ 'name' ] ) );
}
}
我宁愿能够使用第一个选项之一
任何帮助,将不胜感激.
谢谢