Last active
February 14, 2023 22:52
-
-
Save manuelhudec/be1065fdb7137f58117d631e8fda83af to your computer and use it in GitHub Desktop.
WooCommerce - Display Cross-Selling Products in Single Product Summary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('blocksy:woocommerce:product-single:excerpt:after', 'show_cross_sell_in_single_product', 30); | |
function show_cross_sell_in_single_product(){ | |
$crosssells = get_post_meta( get_the_ID(), '_crosssell_ids',true); | |
if(empty($crosssells)){ | |
return; | |
} | |
$args = array( | |
'post_type' => 'product', | |
'posts_per_page' => -1, | |
'post__in' => $crosssells | |
); | |
$products = new WP_Query( $args ); | |
if( $products->have_posts() ) : | |
echo '<div class="cross-sells"><h2>Cross-Sells Products</h2>'; | |
woocommerce_product_loop_start(); | |
while ( $products->have_posts() ) : $products->the_post(); | |
wc_get_template_part( 'content', 'product' ); | |
endwhile; // end of the loop. | |
woocommerce_product_loop_end(); | |
echo '</div>'; | |
endif; | |
wp_reset_postdata(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Manuel, how can I make this paginated?
Kind regards from mickey