代码之家  ›  专栏  ›  技术社区  ›  pipelian

在WooCommerce追加销售(链接产品)之前显示自定义属性

  •  1
  • pipelian  · 技术社区  · 7 年前

    我设法显示自定义属性,但它们显示在链接产品之后。我如何使它们显示在链接产品之前?

    左边:我目前拥有的,右边是期望的结果

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  4
  •   LoicTheAztec    7 年前

    /**
     * woocommerce_after_single_product_summary hook.
     *
     * @hooked woocommerce_output_product_data_tabs - 10
     * @hooked woocommerce_upsell_display - 15
     * @hooked woocommerce_output_related_products - 20
     */
    do_action( 'woocommerce_after_single_product_summary' );
    

    这意味着 woocommerce_after_single_product_summary 钩子,显示以下内容:

    1. 然后(优先级为15)追加销售,
    2. 并完成(优先20项)相关产品。

    woocommerce\u after\u single\u product\u摘要 动作挂钩,优先级在11到14之间。

    add_action('woocommerce_after_single_product_summary', 'custom_code_after_single_product_summary', 12 );
    function custom_code_after_single_product_summary() {
        global $product;
    
        // Set here your post "meta_key" for your custom product attribute
        $meta_key1 = 'pa_when-to-use';
    
        // Your code (related to your comment):
        echo get_post_meta($product->get_id(),  $meta_key1, true);
    }
    

    在WooCommerce 3上测试和工作+