Php Woocommerce html产品描述或带有产品ID的简短描述短代码
我想显示来自另一个woocommerce产品的相同产品说明。因此,创建一个短代码,该短代码按产品获取描述Php Woocommerce html产品描述或带有产品ID的简短描述短代码,php,wordpress,woocommerce,product,shortcode,Php,Wordpress,Woocommerce,Product,Shortcode,我想显示来自另一个woocommerce产品的相同产品说明。因此,创建一个短代码,该短代码按产品获取描述 function get_product_Des( $atts, $content = null ) { extract(shortcode_atts(array( 'product_id' => '' ), $atts)); $ReturnValue = ""; $product
function get_product_Des( $atts, $content = null )
{
extract(shortcode_atts(array(
'product_id' => ''
), $atts));
$ReturnValue = "";
$product = wc_get_product( $product_id );
if($product) $ReturnValue = $product->get_description('edit');
return($ReturnValue);
}
add_shortcode('getproductdes', 'get_product_Des');
但该产品的短代码和原主描述不一样。短代码仅显示文本,它删除了和一些html代码,我是否可以用相同的html代码获得相同的描述。尝试以下重新访问的短代码,以显示定义的产品ID的html格式的产品描述(或产品短描述):
add_shortcode('product_descr', 'display_product_description');
function display_product_description( $atts )
{
extract(shortcode_atts( array(
'post_id' => '',
'short' => '0' // '1' for short description
), $atts));
$content = $short == 0 ? get_the_content(null, false, $post_id) : get_the_excerpt( $post_id );
return wpautop($content);
}
代码进入活动子主题(或活动主题)的functions.php文件。测试和工作
用法示例:
- 有关产品说明:
[产品描述帖子\u id=“37”]
- 对于产品简短描述:
[product\u descr post\u id=“37”short=“1”]
add_shortcode('product_descr', 'display_product_description');
function display_product_description( $atts )
{
extract(shortcode_atts( array(
'post_id' => '',
'short' => '0' // '1' for short description
), $atts));
$content = $short == 0 ? get_the_content(null, false, $post_id) : get_the_excerpt( $post_id );
return wpautop($content);
}
代码进入活动子主题(或活动主题)的functions.php文件。测试和工作
用法示例:
- 有关产品说明:
[产品描述帖子\u id=“37”]
- 对于产品简短描述:
[product\u descr post\u id=“37”short=“1”]