Skip to content

Instantly share code, notes, and snippets.

@dustinleer
Created August 4, 2020 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinleer/17bdacb60decb1a5e83bf9b240dc1c79 to your computer and use it in GitHub Desktop.
Save dustinleer/17bdacb60decb1a5e83bf9b240dc1c79 to your computer and use it in GitHub Desktop.
This will check if upsells are active on the page and if they are none will show the realted products
<?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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment