繁体   English   中英

如何在正常的wordpress中显示woo Commerce产品的产品描述

[英]how to display product description of woo commerce products in normal post of wordpress

我想在woo commerce products的wordpress普通帖子中显示简短的产品描述和其他信息。有没有办法通过短代码或从wordpress中单个帖子文件中的php中做到这一点?

没有内置的短代码可以执行此操作,但是添加一个很容易。 functions.php文件中(最好在您的Child Theme中 ),添加以下内容以创建一个简短代码,例如[product_shortdesc id="123"/]

function product_shortdesc_shortcode( $atts ){
    // use shortcode_atts() to set defaults then extract() to variables
    extract( shortcode_atts( array( 'id' => false ), $atts ) );

    // if an $id was passed, and we could get a Post for it, and it's a product....
    if ( ! empty( $id ) && null != ( $product = get_post( $id ) ) && $product->post_type = 'product' ){
        // apply woocommerce filter to the excerpt
        echo apply_filters( 'woocommerce_short_description', $product->post_excerpt );
    }
}
// process [product_shortdesc] using product_shortdesc_shortcode()
add_shortcode( 'product_shortdesc', 'product_shortdesc_shortcode' );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM