In this documentation, we’ll show you how to automatically disable the checkbox for adding additional order bumps if at least one order bump is already added to the cart. This prevents multiple bumps from being selected.
Note: Customers can always uncheck the current order bump to select a different one.
For this, you need to use a custom code snippet.
Here is the code snippet:
class WFOB_disabled_checkout {
public function __construct() {
add_action( 'wfob_after_add_to_cart', [ $this, 'check_action' ] );
add_action( 'wfob_before_remove_bump_from_cart', [ $this, 'empty_session' ] );
add_filter( 'wfob_disabled_checkbox', [ $this, 'disabled_bump_checkbox' ], 10, 2 );
add_action( 'wfacp_internal_css', [ $this, 'add_js' ] );
}
public function empty_session() {
WC()->session->__unset( 'wfob_bump_checked_key' );
}
public function check_action( $data ) {
if ( ! isset( $data['product_key'] ) || empty( $data['product_key'] ) ) {
return;
}
WC()->session->set( 'wfob_bump_checked_key', $data['product_key'] );
}
public function disabled_bump_checkbox( $status, $product_key ) {
if ( is_null( WC()->session )) {
return $status;
}
$bump_key = WC()->session->get( 'wfob_bump_checked_key' );
if (!empty($bump_key) && $bump_key !== $product_key ) {
$status = true;
echo "<style>.wfob_qv-button{pointer-events: none;}#$product_key{ opacity: .5 !important;background: #dedede;}</style>";
}
return $status;
}
public function add_js() {
?>
<script>
(function ($) {
$(document).ready(function () {
$(document.body).on('click','.wfob_bump_product',function(){
$('.wfob_bump_product').prop('disabled',true);
if ( $(this).is(':checked')){
$(this).prop('disabled',false);
}
});
$(document.body).on('wfacp_step_switching', function (e, v) {
if (typeof v == "undefined") {
return;
}
var next_shown = v.next_shown;
var prev_step = v.hide_parent;
console.log("prev_step",prev_step);
if ("two_step" === prev_step) {
$(document.body).trigger('update_checkout');
// Add Your Script here
}
});
});
})(jQuery);
</script>
<?php
}
}
new WFOB_disabled_checkout();
This snippet will ensure that it automatically disables other order bump checkboxes once one bump is addded in the cart.
