Wordpress 如何按ID显示产品摘要
在我的一个名为Wordpress 如何按ID显示产品摘要,wordpress,woocommerce,Wordpress,Woocommerce,在我的一个名为reservation.php的模板页面中,我想显示一个产品摘要 但Woocommerce仅允许我使用以下短代码显示整个产品页面: [product_page id="99"] 我想要的是只显示其摘要,而不是所有内容 谢谢你的帮助 它不显示任何内容,我将此函数放入函数中。phpad_shortcode('product_data','custom_product_function');函数custom_product_函数($atts){$post_id=$atts['id'];
reservation.php
的模板页面中,我想显示一个产品摘要
但Woocommerce仅允许我使用以下短代码显示整个产品页面:
[product_page id="99"]
我想要的是只显示其摘要,而不是所有内容
谢谢你的帮助
它不显示任何内容,我将此函数放入函数中。phpad_shortcode('product_data','custom_product_function');函数custom_product_函数($atts){$post_id=$atts['id'];$product=wc_get_product($post_id);//添加适用于每种产品类型的数据$product_data=$product->post->post_content;使用快捷码:[product_data id=56]返回$product_data;},您将获得描述将此代码放在function.php中,并在您想要显示的任何页面中显示快捷码。这对您有帮助吗?
<?php
add_shortcode('cat_description', 'my_cat_description_shortcode');
function my_cat_description_shortcode($atts){
$a = shortcode_atts( array( 'id' => 0, ), $atts );
return category_description($a['id']);
}
echo do_shortcode('[cat_description id="' . $category_id . '"]');
?>