Php 在向上销售(链接产品)之前显示自定义属性
我设法显示自定义属性,但它们显示在链接产品之后如何使它们显示在链接产品之前 左边:我现在拥有的,右边是我想要的结果 谢谢Php 在向上销售(链接产品)之前显示自定义属性,php,wordpress,woocommerce,custom-attributes,product,Php,Wordpress,Woocommerce,Custom Attributes,Product,我设法显示自定义属性,但它们显示在链接产品之后如何使它们显示在链接产品之前 左边:我现在拥有的,右边是我想要的结果 谢谢 如果您查看woocommerce模板content-single-product.php,您将看到: /** * woocommerce_after_single_product_summary hook. * * @hooked woocommerce_output_product_data_tabs - 10 * @hooked woocommerce_upsel
如果您查看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' );
这意味着在单产品摘要之后的钩子中,将显示以下内容:
woocommerce\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);
}
代码位于活动子主题(或主题)的function.php文件或任何插件文件中
在WooCommerce 3+上测试并工作正常。。。位置已经确定,但现在我无法显示帖子的自定义属性,我在single-product.php上有一段代码:,其中“TABLE”是自定义属性的名称,非常感谢!这对我有用。谢谢,我的朋友们投我一票side@LoicTheAztec,谢谢你的指导。。位置已确定,但现在我无法显示帖子的自定义属性,我在single-product.php上有一段代码,我已将其移动到mu functions.php文件中:add_action('woocommerce_之后是single_产品_摘要','custom_代码_之后是single_产品_摘要',12);函数自定义_-code_-after_-single_-product_-summary(){global$product;//=>您的代码在这里回显“产品ID:”。获取_-post_-meta($post->ID,'TABLE',true)。“”;}