Last active
March 27, 2018 15:24
-
-
Save Basilakis/edacbd2c8d327fa569c480d33a74870a to your computer and use it in GitHub Desktop.
Dynamic Fees for Shipping Per Payment GateWay for WooCommerce
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
add_action('init', 'cg_init'); | |
function cg_init() { | |
add_action('woocommerce_cart_calculate_fees', 'cg_add_fee'); | |
add_action('wp_footer', 'cg_footer', 9999); | |
} | |
function cg_footer() { | |
?> | |
<script type="text/javascript"> | |
jQuery(function($) { | |
setInterval(function() { | |
$(".input-radio[name='payment_method']").off().change(function() { | |
console.log('triggered'); | |
jQuery('body').trigger('update_checkout'); | |
}); | |
}, 500); | |
}); | |
</script> | |
<?php | |
} | |
function cg_add_fee($the_cart) { | |
global $woocommerce; | |
$amount = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) ); | |
if ( $amount < 50 && $woocommerce->customer->get_billing_country() == 'GR' ) { | |
if ($woocommerce->session->chosen_payment_method == 'cod') { | |
$woocommerce->cart->add_fee('Shipping Cost', '5', true, 'standard'); | |
} else { | |
$woocommerce->cart->add_fee('Shipping Cost', '3', true, 'standard'); | |
} | |
} else { | |
$woocommerce->cart->add_fee('Shipping Cost - Free Shipping', '0', true, 'standard'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment