admin管理员组文章数量:1291095
I have created a shortcode to show all woocommerce products in a new page with all woocommerce filter and pagination but it seems only products are showing
ob_start();
$products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
if ( $products->have_posts() ) : ?>
<?php do_action( 'woocommerce_before_shop_loop' ); //this would show post count and filter ?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php do_action( 'woocommerce_after_shop_loop' ); //this would show pagination ?>
<?php endif;?>
<?php
wp_reset_postdata();
?>
<?php
return '<div class="woocommerce columns-' . $column . '">' . ob_get_clean() . '</div>';
According to woocommerce archive-products.php template woocommerce_before_shop_loop
should show count and filter
And woocommerce_after_shop_loop
show pagination but here its not working.Any alternative to show them?
Full shortcode for wc-visual composer :
I have created a shortcode to show all woocommerce products in a new page with all woocommerce filter and pagination but it seems only products are showing
ob_start();
$products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
if ( $products->have_posts() ) : ?>
<?php do_action( 'woocommerce_before_shop_loop' ); //this would show post count and filter ?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php do_action( 'woocommerce_after_shop_loop' ); //this would show pagination ?>
<?php endif;?>
<?php
wp_reset_postdata();
?>
<?php
return '<div class="woocommerce columns-' . $column . '">' . ob_get_clean() . '</div>';
According to woocommerce archive-products.php template woocommerce_before_shop_loop
should show count and filter
And woocommerce_after_shop_loop
show pagination but here its not working.Any alternative to show them?
Full shortcode for wc-visual composer : https://pastebin/crv4jwsz
Share Improve this question asked Aug 20, 2017 at 4:58 user126188user126188 11 silver badge1 bronze badge1 Answer
Reset to default 1In core WooCommerce, the pagination is added via the woocommerce_pagination()
function hooked to woocommerce_after_shop_loop
, and the sorting and result counts are output by the woocommerce_result_count()
and woocommerce_catalog_ordering()
functions. If you look at the source for these functions, you can see that they display according to the main $wp_query
, which will not contain any products because you're querying posts with your own WP_Query.
So this might be one of those very rare occasions where query_posts()
would be the right thing to do. If you use query_posts()
in place of a secondary WP_Query, then those template functions should reflect your custom query.
ob_start();
query_posts( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
if ( have_posts() ) : ?>
<?php do_action( 'woocommerce_before_shop_loop' ); //this would show post count and filter ?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php do_action( 'woocommerce_after_shop_loop' ); //this would show pagination ?>
<?php endif;?>
<?php
wp_reset_postdata();
wp_reset_query();
return '<div class="woocommerce columns-' . $column . '">' . ob_get_clean() . '</div>';
Take note of the wp_reset_query()
, that's very important here.
I'm not sure pagination will work correctly though, you might need to use your own instance of paginate_links()
, refer to the documentation in the codex for examples of using paginate_links()
with a custom query.
本文标签: Woocommerce before and after shop loop not works
版权声明:本文标题:Woocommerce before and after shop loop not works 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741505552a2382298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论