Created
June 16, 2025 14:10
-
-
Save xlplugins/98971a0ce16d61d204696dfebe830f33 to your computer and use it in GitHub Desktop.
run update checkout on product switcher event
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_Compatibility_Re_run_update_review { | |
private $process = false; | |
public function __construct() { | |
add_action( 'wp_footer', [ $this, 'js' ] ); | |
add_action( 'woocommerce_checkout_update_order_review', [ $this, 'get_data' ], 5 ); | |
add_filter( 'woocommerce_update_order_review_fragments', [ $this, 'unset_fragments' ], 900 ); | |
} | |
private function is_enabled() { | |
return true; | |
} | |
public function get_data( $data ) { | |
if ( false == $this->is_enabled() ) { | |
return $data; | |
} | |
if ( empty( $data ) ) { | |
return $data; | |
} | |
parse_str( $data, $post_data ); | |
if ( empty( $post_data ) ) { | |
return $data; | |
} | |
if ( empty( $bump_action_data ) && isset( $post_data['wfacp_input_hidden_data'] ) && ! empty( $post_data['wfacp_input_hidden_data'] ) ) { | |
$bump_action_data = json_decode( $post_data['wfacp_input_hidden_data'], true ); | |
} | |
if ( isset( $bump_action_data['bump_unset_fragments'] ) ) { | |
$this->process = true; | |
} | |
} | |
public function unset_fragments( $fragments ) { | |
if ( false == $this->process ) { | |
return $fragments; | |
} | |
foreach ( $fragments as $k => $fragment ) { | |
if ( ( false !== strpos( $k, 'wfacp' ) || false !== strpos( $k, 'wfob' ) ) && true == apply_filters( 'wfob_unset_our_fragments_by_paypal_gmbh', true, $k ) ) { | |
unset( $fragments[ $k ] ); | |
} | |
} | |
unset( $fragments['cart_total'] ); | |
return $fragments; | |
} | |
public function js() { | |
if ( false == $this->is_enabled() || ! is_checkout() ) { | |
return; | |
} | |
?> | |
<script> | |
window.addEventListener('load', function () { | |
(function ($) { | |
wfacp_frontend.hooks.addFilter('wfacp_before_ajax_data_update_product_qty', set_custom_data); | |
wfacp_frontend.hooks.addFilter('wfacp_before_ajax_data_update_cart_item_quantity', set_custom_data); | |
wfacp_frontend.hooks.addFilter('wfacp_before_ajax_data_wfacp_restore_cart_item', set_custom_data); | |
wfacp_frontend.hooks.addFilter('wfacp_before_ajax_data_switch_product_addon', set_custom_data); | |
wfacp_frontend.hooks.addFilter('wfacp_before_ajax_data_addon_product', set_custom_data); | |
wfacp_frontend.hooks.addAction('wfacp_ajax_response', trigger_checkout); | |
function set_custom_data(data) { | |
console.log('data',data); | |
data['bump_unset_fragments'] = 'yes'; | |
return data; | |
} | |
function trigger_checkout(rsp) { | |
$(document.body).trigger('update_checkout'); | |
} | |
})(jQuery); | |
}); | |
</script> | |
<?php | |
} | |
} | |
new WFOB_Compatibility_Re_run_update_review(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment