Last active
November 26, 2025 05:43
-
-
Save xlplugins/6aa474ff8c09944dbce968aaa18954eb to your computer and use it in GitHub Desktop.
FunnelKit OrderBump Auto-Select & Cart Total Exclusion
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 WFOB_Bump_Pre_Select_Fix { | |
| /** | |
| * OrderBump IDs to auto-select | |
| * | |
| * @var array | |
| */ | |
| private $bump_ids = array( 5503 ); // Your OrderBump IDs here in comma separated 2363, 2302, 2895 | |
| /** | |
| * Initialize the class | |
| */ | |
| public function __construct() { | |
| // Filter to exclude bump items from cart total calculations | |
| add_filter( 'wfob_exclude_bump_price_from_cart_total', array( $this, 'exclude_bump_price_from_cart_total' ), 999999, 3 ); | |
| // Add footer script for auto-selecting order bumps | |
| add_action( 'wp_footer', array( $this, 'footer_scripts' ) ); | |
| } | |
| /** | |
| * Exclude bump items from cart total calculations | |
| * | |
| * @param bool $status Current status | |
| * @param array $cart_item Cart item data | |
| * @param string $class_name Class name | |
| * @return bool | |
| */ | |
| public function exclude_bump_price_from_cart_total( $status, $cart_item, $class_name = '' ) { | |
| if ( isset( $cart_item['_wfob_product'] ) ) { | |
| return false; | |
| } | |
| //echo $cart_item['_wfob_pre_checked']."<br>"; | |
| //echo $cart_item['product_id']." - ".$cart_item['_wfob_pre_checked']."<br>"; | |
| //WFACP_Common::pr($cart_item); | |
| return $status; // Exclude bump items | |
| } | |
| /** | |
| * Output JavaScript for auto-selecting order bumps | |
| */ | |
| public function footer_scripts() { | |
| $bump_ids_json = wp_json_encode( $this->bump_ids ); | |
| ?> | |
| <script> | |
| (function ($) { | |
| let bumps_ids = <?php echo $bump_ids_json; ?>; // Your OrderBump IDs here in comma separated 2363, 2302, 2895 | |
| let added = []; | |
| $(document.body).on('updated_checkout', function () { | |
| setTimeout(function () { | |
| jQuery('input.wfob_choose_variation').removeClass('wfob_choose_variation').addClass('wfob_bump_product'); | |
| jQuery('a.wfob_choose_variation').removeClass('wfob_choose_variation').addClass('wfob_bump_product'); | |
| let already_added = 0; | |
| for (let i = 0; i < bumps_ids.length; i++) { | |
| let bump = $(`.wfob_bump[data-wfob-id=${bumps_ids[i]}]`); | |
| if (undefined !== bump.attr('cart_key') && '' !== bump.attr('cart_key')) { | |
| already_added++ | |
| } | |
| } | |
| if (added.length === bumps_ids.length || bumps_ids.length == already_added) { | |
| return; | |
| } | |
| for (let i = 0; i < bumps_ids.length; i++) { | |
| if (added.indexOf(bumps_ids[i]) > -1) { | |
| continue; | |
| } | |
| let bump_div = $(`.wfob_wrapper[data-wfob-id="${bumps_ids[i]}"]`); | |
| if (bump_div.length > 0) { | |
| bump_div.find('.wfob_bump_product').trigger('click') | |
| added.push(bumps_ids[i]); | |
| } | |
| // break; | |
| } | |
| }, 200); | |
| }); | |
| })(jQuery); | |
| </script> | |
| <?php | |
| } | |
| } | |
| // Initialize the class | |
| new WFOB_Bump_Pre_Select_Fix(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment