Php WooCommerce产品附加信息短代码
我是WooCommerce的新手,正在寻找一种在帖子页面上显示产品属性的解决方案。 我做了一些研究和测试,但似乎没有任何效果 理想情况下,我希望使用一个短代码获取产品ID并在我的帖子页面上显示他的所有产品属性。Php WooCommerce产品附加信息短代码,php,wordpress,woocommerce,shortcode,custom-taxonomy,Php,Wordpress,Woocommerce,Shortcode,Custom Taxonomy,我是WooCommerce的新手,正在寻找一种在帖子页面上显示产品属性的解决方案。 我做了一些研究和测试,但似乎没有任何效果 理想情况下,我希望使用一个短代码获取产品ID并在我的帖子页面上显示他的所有产品属性。 类似于[product\u page id=99 display\u only\u attributes]这里是在自定义短代码中获取产品属性的方法,您将在其中将产品id定义为短代码参数id 功能代码: if ( ! function_exists( 'display_product_ad
类似于[product\u page id=99 display\u only\u attributes]这里是在自定义短代码中获取产品属性的方法,您将在其中将产品id定义为短代码参数id 功能代码:
if ( ! function_exists( 'display_product_additional_information' ) ) {
function display_product_additional_information($atts) {
// Shortcode attribute (or argument)
$atts = shortcode_atts( array(
'id' => ''
), $atts, 'product_additional_information' );
// If the "id" argument is not defined, we try to get the post Id
if ( ! ( ! empty($atts['id']) && $atts['id'] > 0 ) ) {
$atts['id'] = get_the_id();
}
// We check that the "id" argument is a product id
if ( get_post_type($atts['id']) === 'product' ) {
$product = wc_get_product($atts['id']);
}
// If not we exit
else {
return;
}
ob_start(); // Start buffering
do_action( 'woocommerce_product_additional_information', $product );
return ob_get_clean(); // Return the buffered outpout
}
add_shortcode('product_additional_information', 'display_product_additional_information');
}
代码进入活动子主题或活动主题的function.php文件。测试和工作
短代码使用更新
使用定义的产品id:
[product_additional_information id='37']
或在php中:
echo do_shortcode("[product_additional_information id='37']");
echo do_shortcode("[product_additional_information]");
在现有产品页面中,删除附加信息“产品”选项卡时,例如:
或在php中:
echo do_shortcode("[product_additional_information id='37']");
echo do_shortcode("[product_additional_information]");
你会得到这样的结果:
以下是在自定义短代码中获取产品属性的方法,您将在中将产品ID定义为短代码参数ID 功能代码:
if ( ! function_exists( 'display_product_additional_information' ) ) {
function display_product_additional_information($atts) {
// Shortcode attribute (or argument)
$atts = shortcode_atts( array(
'id' => ''
), $atts, 'product_additional_information' );
// If the "id" argument is not defined, we try to get the post Id
if ( ! ( ! empty($atts['id']) && $atts['id'] > 0 ) ) {
$atts['id'] = get_the_id();
}
// We check that the "id" argument is a product id
if ( get_post_type($atts['id']) === 'product' ) {
$product = wc_get_product($atts['id']);
}
// If not we exit
else {
return;
}
ob_start(); // Start buffering
do_action( 'woocommerce_product_additional_information', $product );
return ob_get_clean(); // Return the buffered outpout
}
add_shortcode('product_additional_information', 'display_product_additional_information');
}
代码进入活动子主题或活动主题的function.php文件。测试和工作
短代码使用更新
使用定义的产品id:
[product_additional_information id='37']
或在php中:
echo do_shortcode("[product_additional_information id='37']");
echo do_shortcode("[product_additional_information]");
在现有产品页面中,删除附加信息“产品”选项卡时,例如:
或在php中:
echo do_shortcode("[product_additional_information id='37']");
echo do_shortcode("[product_additional_information]");
你会得到这样的结果:
我只想让它们像通常在产品页面上一样显示在我的博文页面上。但只有附加信息部分包含属性。没有html,只有wordpress后端。目标是我公司的内容团队能够使用任何进入WooCad的产品,并将其属性显示在页面的中间。这是一个简单的产品,它也会显示变化。所以你想在产品列表页面上显示所有属性,产品方面。当然不是在产品页面上,而是在发布页面上。我们目前正在建立一个汽车评论网站。每辆车都将进入woocommerce,并具有与每辆车相关的所有指定属性。这些评论是作为普通的博客文章写的。当内容团队写一篇关于汽车的评论时,我希望他们能够使用一个短代码来引用woocommerce中输入的汽车ID,这将在文章中列出它的所有属性,工作非常完美!Merci beaucoup:我只希望它们像通常在产品页面上一样显示在我的博文页面上。但只有附加信息部分包含属性。没有html,只有wordpress后端。目标是我公司的内容团队能够使用任何进入WooCad的产品,并将其属性显示在页面的中间。这是一个简单的产品,它也会显示变化。所以你想在产品列表页面上显示所有属性,产品方面。当然不是在产品页面上,而是在发布页面上。我们目前正在建立一个汽车评论网站。每辆车都将进入woocommerce,并具有与每辆车相关的所有指定属性。这些评论是作为普通的博客文章写的。当内容团队写一篇关于汽车的评论时,我希望他们能够使用一个短代码来引用woocommerce中输入的汽车ID,这将在文章中列出它的所有属性,工作非常完美!谢天谢地: