在 WooCommerce 产品页面中显示自定义产品属性值

时间:2021-02-11 19:25:03

标签: php wordpress woocommerce attributes product

我将向 woocommerce 目录中产品的产品数据添加自定义产品属性。<​​/p>

如何获取该字段的值以显示在产品页面/模板中?

谢谢

enter image description here

1 个答案:

答案 0 :(得分:3)

您可以使用 WC_Product get_attribute() 方法使用以下内容:

global $product; // if the WC_Product object is not defined

if ( ! is_a($product, 'WC_Product') ) {
    $product = wc_get_product( get_the_ID() );
}

echo  '<p>' . $product->get_attribute( 'secimg' ) . '</p>';

它应该可以工作。