在WooCommerce产品摘要中显示产品维度

问题描述 投票:1回答:1

在WooCommerce中,我想在单个产品页面的摘要中显示产品元数据中的产品尺寸。可能吗?

任何曲目都表示赞赏。


编辑 - 更多细节:

我在我的主题设置中有一个选项,如下所示: Theme Setting Option

当我启用此选项时,我的产品页面如下图所示: Single Product Page 我想从我的主题设置中禁用此选项,然后使用代码段仅显示尺寸。

php wordpress woocommerce product dimensions
1个回答
1
投票

以下钩子函数将在产品单页的产品简短描述下显示格式化的产品尺寸(仅限):

add_action( 'woocommerce_single_product_summary', 'display_product_formated_dimensions_table', 25 );
function display_product_formated_dimensions_table(){
    global $product;

    if ( $product->has_dimensions() ) {
        echo '<table class="shop_attributes"><tr>
            <th>' . __( 'Dimensions', 'woocommerce' ) . '</th>
            <td class="product_dimensions">' . esc_html( wc_format_dimensions( $product->get_dimensions( false ) ) ) . '</td>
        </tr></table>';
    }
}

代码位于活动子主题(或活动主题)的function.php文件中。经过测试和工作。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.