Woocommerce产品摘要短代码

Woocommerce产品摘要短代码,woocommerce,shortcode,hook-woocommerce,Woocommerce,Shortcode,Hook Woocommerce,我并不懒惰,我自己也尝试过,但是失败了。我想为Woocomece single product创建一个短代码,以显示产品摘要。我想知道你是否知道如何做到这一点。谢谢以下代码片段将创建一个短代码,如下所示: [产品描述产品id=“633”] /** *注册产品描述短代码 * *@param array$atts“product_id”是唯一受支持的属性 * */ 功能起亚和简短描述($atts){ 如果(!function_存在('woocommerce_template_single_ext

我并不懒惰,我自己也尝试过,但是失败了。我想为Woocomece single product创建一个短代码,以显示产品摘要。我想知道你是否知道如何做到这一点。谢谢

以下代码片段将创建一个短代码,如下所示:
[产品描述产品id=“633”]

/**
*注册产品描述短代码
* 
*@param array$atts“product_id”是唯一受支持的属性
* 
*/
功能起亚和简短描述($atts){
如果(!function_存在('woocommerce_template_single_extract')){
返回“”;
}
$atts=短码_atts(数组)(
“产品标识”=>0
),$atts,“产品描述”);
全球$员额;
$backup_post=$post;
//如果不是当前邮局,则临时覆盖$post对象。
如果(0<$atts['product_id']){
$post=get_post($atts['product_id']);
}
//获取简短描述模板:
ob_start();
woocommerce_模板_single_摘录();
$html=ob_get_clean();
//还原原始$post对象。
$post=$backup\U post;
返回$html;
}
添加短代码(“产品描述”、“起亚和短描述”);

什么是产品摘要?
/**
 * Register product_description shortcode
 * 
 * @param array $atts 'product_id' is the only supported attribute
 * 
 */
function kia_woo_short_description( $atts ) {

    if( ! function_exists( 'woocommerce_template_single_excerpt' ) ) {
        return '';
    }

    $atts = shortcode_atts( array(
        'product_id' => 0
    ), $atts, 'product_description' );

    global $post;
    $backup_post    = $post;

    // If not the current post store then temporarily override the $post object.
    if( 0 < $atts['product_id'] ) {
        $post = get_post( $atts['product_id']);

    }

    // Get the short description template:
    ob_start();
    woocommerce_template_single_excerpt();
    $html = ob_get_clean();

    // Restore original $post object.
    $post    = $backup_post;

    return $html;


}
add_shortcode( 'product_description', 'kia_woo_short_description' );