我想在woocommerce中获得特定的自定义属性.我已经在这个网站上阅读了大量的线程,提供了大约3-5种方法.在尝试了所有之后,对我有用的唯一方法是遍历所有属性 - 所有其他属性都不起作用.我有一个名为'pdfs'的自定义属性
下面的尝试没有工作: (链接)
$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);
Run Code Online (Sandbox Code Playgroud)
这是做的工作只有一个: (链接)
$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' ] ) );
}
}
Run Code Online (Sandbox Code Playgroud)
我宁愿能够使用第一个选项之一任何帮助将不胜感激.
谢谢
我正在我正在使用的网站上使用woocommerce,我想在结帐页面的顶部显示当前的产品缩略图,因此用户可以查看他要购买的内容.
但是我找不到任何办法.
我得到的最接近的是使用WC::cart->get_cart(),但是这会输出所有产品的列表.
我怎样才能做到这一点?
谢谢