Created
July 8, 2025 08:37
-
-
Save xlplugins/9a403efd6838c054e915dbb6b6de404a to your computer and use it in GitHub Desktop.
Disable upsell specific product reference snippet
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
class FKCart_Disable_Upsells { | |
public function __construct() { | |
add_action( 'fkcart_before_cart_items', [ $this, 'init_filters' ] ); | |
} | |
public function init_filters() { | |
add_filter( 'woocommerce_product_get_upsell_ids', [ $this, 'remove_upsell_ids' ], 10, 2 ); | |
add_filter( 'woocommerce_product_get_cross_sell_ids', [ $this, 'remove_cross_sell_ids' ], 10, 2 ); | |
add_filter( 'fkcart_default_upsells', [ $this, 'remove_fkcart_default_upsells' ] ); | |
} | |
public function remove_upsell_ids( $upsell_ids, $product ) { | |
// Remove all upsell IDs | |
return []; | |
// Example to keep upsells for specific products only: | |
/* | |
if ( in_array( $product->get_id(), [123, 456], true ) ) { | |
return []; | |
} | |
return $upsell_ids; | |
*/ | |
} | |
public function remove_cross_sell_ids( $cross_sell_ids, $product ) { | |
// Remove all cross-sell IDs | |
return []; | |
} | |
public function remove_fkcart_default_upsells() { | |
// Remove all default upsells | |
return []; | |
} | |
} | |
// Initialize the class | |
new FKCart_Disable_Upsells(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment