将行添加到 WooCommerce 3.6 中的单一产品附加信息表

Akh*_*uvo 3 php wordpress product woocommerce hook-woocommerce

我正在尝试向单一产品附加信息表添加一行。

截屏

实际上有没有任何钩子或过滤器可以做到这一点?我已经搜索过该钩子但无法找出解决方案。

任何帮助表示赞赏。

Loi*_*tec 6

从 WooCommerce版本 3.6开始,您可以通过这种简单的方式使用过滤器挂钩,在“附加信息”表(选项卡)woocommerce_display_product_attributes中添加自定义标签/值对:

add_filter( 'woocommerce_display_product_attributes', 'custom_product_additional_information', 10, 2 );
function custom_product_additional_information( $product_attributes, $product ) {
    // First row
    $product_attributes[ 'attribute_' . 'custom-one' ] = array(
        'label' => __('Label One'),
        'value' => __('Value 1'),
    );

    // Second row
    $product_attributes[ 'attribute_' . 'custom-two' ] = array(
        'label' => __('Label Two'),
        'value' => __('Value 2'),
    );

    return $product_attributes;
}
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述