简体   繁体   English

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

[英]Display custom attributes before WooCommerce upsells ( linked products)

I manage to display the custom attributes but they are shown after linked products how can I make them appear before? 我设法显示自定义属性,但是在链接产品之后显示它们,如何使它们出现在前面?

On the left: what I currently have, right desired result 左侧:我目前所拥有的,理想的结果

Thanks 谢谢 在此处输入图片说明

If you look to the woocommerce template content-single-product.php you will see that: 如果查看woocommerce模板content-single-product.php,您将看到:

/**
 * 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' );

That means that in the woocommerce_after_single_product_summary hook, the following is displayed: 这意味着在woocommerce_after_single_product_summary挂钩中,将显示以下内容:

  1. First (with a priority of 10) The product tabs, 首先(优先级为10)产品标签,
  2. Then (with a priority of 15) The upsells, 然后(优先级为15)加售,
  3. And to finish (with a priority of 20) The related products. 并完成(优先级为20)相关产品。

So if you want to display your custom code between the product tabs and the upsells, you will need to use a custom function hooked in woocommerce_after_single_product_summary action hook with a priority between 11 to 14. 因此,如果要在产品标签woocommerce_after_single_product_summary售之间显示自定义代码,则需要使用挂钩在woocommerce_after_single_product_summary操作挂钩中的自定义函数,其优先级在11到14之间。

You can do it this way: 您可以这样操作:

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);
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file. 代码在您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。

Tested and works on WooCommerce 3+… 经过测试,可在WooCommerce 3+上运行…

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在woocommerce存档页面和加售/相关产品中显示自定义产品价格 - Display a custom product price in woocommerce archive page and for upsells/related products 显示 WooCommerce 自定义产品属性和单个产品的所有条款 - Display WooCommerce Custom Product Attributes and all terms on single products 在链接产品选项卡(在 woocommerce 中)的管理面板中搜索追加销售和交叉销售时,如何添加过滤器以隐藏缺货产品? - How to add filter to hide out of stock products when searching for Upsells and Cross-sells in admin panel on the Linked Products tab (in woocommerce)? Woocommerce类别页面在产品之前显示此自定义字段 - Woocommerce category page display this custom field before products 在Woocommerce变量产品的变体描述之前自定义显示 - Custom display before variation description on Woocommerce variable products 在Woocommerce 3中用特定产品类别的产品替换加售商品 - Replace Upsells with products from a specific product category in Woocommerce 3 列出所有变体,显示其与 Woocommerce 产品循环上的变体相关联的属性 - List all variations displaying their attributes linked to the variation on Woocommerce products loop 如何在 WooCommerce 结帐页面上显示购物车项目加售? - How to display cart items upsells on WooCommerce checkout page? 在 WooCommerce 折扣产品上显示自定义价格后缀 - Display custom price suffix on WooCommerce discounted products 在 Woocommerce 单个产品的标题前添加链接的特定产品属性 - Add linked specific product attribute before title on Woocommerce single products
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM