Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 7 years ago.
Improve this questionI am trying to show cross sells on a single product page rather than in the cart:
So far I've tried the following code:
<?php do_action( 'woocommerce_after_single_product_summary_data_tabs' ); ?>
<?php if ( $product->get_upsell_ids() ) : ?>
<div class="single_product_summary_upsell">
<?php do_action( 'woocommerce_after_single_product_summary_upsell_display' ); ?>
</div><!-- .single_product_summary_upsells -->
<?php endif; ?>
<?php if ( $product->get_cross_sell_ids() ) : ?>
<div class="single_product_summary_upsell">
<?php do_action( 'woocommerce_after_single_product_summary_upsell_display' ); ?>
</div><!-- .single_product_summary_upsells -->
<?php endif; ?>
<div class="single_product_summary_related">
<?php do_action( 'woocommerce_after_single_product_summary_related_products' ); ?>
</div><!-- .single_product_summary_related -->
</div><!-- .columns -->
However this will only show upsells below upsells, so it's just the same content twice. I am not sure on what action to use instead of
do_action( 'woocommerce_after_single_product_summary_upsell_display' ); ?>
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 7 years ago.
Improve this questionI am trying to show cross sells on a single product page rather than in the cart:
So far I've tried the following code:
<?php do_action( 'woocommerce_after_single_product_summary_data_tabs' ); ?>
<?php if ( $product->get_upsell_ids() ) : ?>
<div class="single_product_summary_upsell">
<?php do_action( 'woocommerce_after_single_product_summary_upsell_display' ); ?>
</div><!-- .single_product_summary_upsells -->
<?php endif; ?>
<?php if ( $product->get_cross_sell_ids() ) : ?>
<div class="single_product_summary_upsell">
<?php do_action( 'woocommerce_after_single_product_summary_upsell_display' ); ?>
</div><!-- .single_product_summary_upsells -->
<?php endif; ?>
<div class="single_product_summary_related">
<?php do_action( 'woocommerce_after_single_product_summary_related_products' ); ?>
</div><!-- .single_product_summary_related -->
</div><!-- .columns -->
However this will only show upsells below upsells, so it's just the same content twice. I am not sure on what action to use instead of
do_action( 'woocommerce_after_single_product_summary_upsell_display' ); ?>
add_action('woocommerce_after_single_product_summary', '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();
}
find this code and remove it
1: get the ids of the cross sell products using the ‘_crosssell_ids’ meta key.
<?php
/* crossells */
$crosssell_ids = get_post_meta( get_the_ID(), '_crosssell_ids' );
$crosssell_ids=$crosssell_ids[0];
?>
if(count($crosssell_ids)>0){
$args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'post__in' => $crosssell_ids );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?><a href='<?php the_permalink(); ?>'><?php
the_post_thumbnail( 'thumbnail' );
the_title();
?></a><?php
endwhile;
}