Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created February 28, 2025 10:39
Show Gist options
  • Save webtoffee-git/1c388a0540be82be85993c7c2b2c9b50 to your computer and use it in GitHub Desktop.
Save webtoffee-git/1c388a0540be82be85993c7c2b2c9b50 to your computer and use it in GitHub Desktop.
Code snippet to ensure compatibility between the Smart Coupons for WooCommerce, Side Cart WooCommerce, and Mercado Pago plugins - By WebToffee( Smart Coupon For WooCommerce Plugin)
//Do not copy this line of code
/**
* Set block checkout values on page load.
*/
add_action( 'wp_head', function() {
?>
<script>
jQuery(document).ready(function($){
setTimeout(() => wbte_set_block_checkout_values(), 100);
function wbte_set_block_checkout_values() {
let payment_method = '';
let shipping_method = {};
if( $('[name="radio-control-wc-payment-method-options"]').length ) {
/* Prepare payment method from radio button */
payment_method = $('[name="radio-control-wc-payment-method-options"]:checked').val();
}
/* Prepare shipping method from radio button */
if( $('.wc-block-components-shipping-rates-control input[type="radio"]').length ) {
$('.wc-block-components-shipping-rates-control input[type="radio"]:checked').each(function(){
let prefix = $(this).attr('name').split('-').pop();
shipping_method[prefix] = $(this).val();
});
}
WTSmartCouponOBJ.shipping_method = shipping_method;
WTSmartCouponOBJ.payment_method = payment_method;
$.ajax({
type: "POST",
async: true,
url: WTSmartCouponOBJ.wc_ajax_url + 'wbte_sc_set_block_checkout_values',
data: { '_wpnonce': WTSmartCouponOBJ.nonces.public, 'payment_method': payment_method, 'shipping_method': shipping_method },
dataType: 'json',
success:function( data ) {
},
});
}
});
</script>
<?php
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment