WooCommerce Custom Loop in Template Page, shows only 2 products but it dumps 6 (right query limit)
<?php | |
defined( 'ABSPATH' ) || exit; | |
global $product; | |
// Ensure visibility. | |
if ( empty( $product ) || ! $product->is_visible() ) { | |
return; | |
} | |
$vendor = dokan_get_vendor_by_product($product->get_id()); | |
$store = dokan_get_store_info($vendor->id); | |
/** | |
* Hook: woocommerce_before_shop_loop_item. | |
* | |
* @hooked woocommerce_template_loop_product_link_open - 10 | |
*/ | |
do_action( 'woocommerce_before_shop_loop_item' ); | |
?> | |
<div <?php wc_product_class( 'brewery-item hb-card card-beer', $product ); ?>> | |
<?php | |
do_action( 'hbeer_product_content_thumbnail' ); | |
?> | |
<div class="card--content"> | |
<?php | |
do_action( 'hbeer_product_content_vendor' ); | |
?> | |
<div class="card--title"> | |
<?php | |
do_action( 'woocommerce_before_shop_loop_item_title' ); | |
do_action( 'woocommerce_shop_loop_item_title' ); | |
do_action('woocommerce_after_shop_loop_item_title'); | |
?> | |
</div> | |
<div class="card--meta"> | |
<?php | |
do_action( 'hbeer_content_product_taxonomies' ); | |
do_action( 'hbeer_content_product_price' ); | |
?> | |
</div> | |
<?php | |
do_action( 'hbeer_content_product_store_address' ); | |
do_action( 'hbeer_content_product_description' ); | |
?> | |
</div> | |
</div> | |
<?php | |
/** | |
* Hook: woocommerce_after_shop_loop_item. | |
* | |
* @hooked woocommerce_template_loop_product_link_close - 5 | |
*/ | |
do_action( 'woocommerce_after_shop_loop_item' ); | |
?> |
<?php | |
add_action( 'genesis_entry_content', 'hbeer_products_loop', 8 ); | |
// Add general WooCommerce Loop | |
function hbeer_products_loop() { | |
if( !function_exists( 'wc_get_products' ) ) { | |
return; | |
} | |
$products = wc_get_products( | |
[ | |
'status' => 'publish', | |
] | |
); | |
wc_set_loop_prop('page_template', get_page_template_slug()); | |
if( $products ){ | |
do_action('woocommerce_before_shop_loop'); | |
woocommerce_product_loop_start(); | |
foreach( $products as $product ){ | |
$product_object = get_post( $product->get_id() ); | |
var_dump( $product_object ); | |
setup_postdata( $GLOBALS['post'] =& $product_object ); | |
wc_get_template_part( 'content', 'product' ); | |
} | |
wp_reset_postdata(); | |
woocommerce_product_loop_end(); | |
do_action('woocommerce_after_shop_loop'); | |
} | |
} | |
// Forces full width content layout. | |
add_filter( 'genesis_site_layout', '__genesis_return_full_width_content' ); | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment