Remove Related if Using Upsells
-
My goal is to remove Related Products if I am using Upsells on a product page.
I do not know php but have common sense.
I found some code which removes the Related Products, however my problem is that it duplicates 3 of the Upsells at the bottom. On the page I linked to(https://bit.ly/2noW6Wm), there should only be 6 upsells products. ‘You may also like…’ begins again.
I have disabled plugins, looked for ‘related posts/products’ settings to no avail. When I take out the code I used below, the problem goes away so I assume the replication is coming from the code. I could be wrong of course.
Any advice on how to get rid of the duplicate listing? Thank you in advance, I’ve tried and can’t seem to get it right or come up with an alternative.
————————————-
this was added to my functions.php// REMOVE RELATED IF UPSELLS
remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_upsell_display’, 15 );
remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 );add_action( ‘woocommerce_after_single_product_summary’, ‘related_upsell_products’, 15 );
function related_upsell_products() {
global $product;if ( isset( $product ) && is_product() ) {
$upsells = $product->get_upsells();if ( sizeof( $upsells ) > 0 ) {
woocommerce_upsell_display();
} else {
woocommerce_upsell_display();
woocommerce_output_related_products();
}
}
}The page I need help with: [log in to see the link]
- The topic ‘Remove Related if Using Upsells’ is closed to new replies.