【发布时间】:2021-02-15 18:22:42
【问题描述】:
我正在尝试在我的帐户仪表板页面中显示相关产品。我关注了这个WooCommerce Shortcodes documentation。
我尝试使用以下代码:
add_action( 'woocommerce_account_content', 'output_shortcode_on_child_pages');
function output_shortcode_on_child_pages() {
$post = get_post();
if ( is_page() AND $post->post_parent ) {
echo do_shortcode( '[related_products limit=”3″]' );
}
}
这不显示相关产品。但是当我尝试在特定类别中显示产品时,如下所示,它可以工作:
add_action( 'woocommerce_account_content', 'output_shortcode_on_child_pages');
function output_shortcode_on_child_pages() {
$post = get_post();
if ( is_page() AND $post->post_parent ) {
echo do_shortcode( '[products limit="3" columns="3" orderby="rand" category=”presets-and-actions” ]' );
}
}
请帮忙解决这个问题?
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce shortcode