[英]Display custom attributes before WooCommerce upsells ( linked products)
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
挂钩中,将显示以下内容:
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.