Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_cart_calculate_fees', 'mx_checkout_fee_for_cod' );
- function mx_checkout_fee_for_cod() {
- $chosen_gateway = WC()->session->get( 'chosen_payment_method' );
- $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
- $chosen_shipping = $chosen_methods[0];
- if ( $chosen_gateway == 'cod' && 0 === strpos( $chosen_shipping, 'mx_local_shipping' )){
- WC()->cart->add_fee( 'Naknada za plaćanje pouzećem', 0 );
- }
- else {
- if ( $chosen_gateway == 'cod'){
- WC()->cart->add_fee( 'Naknada za plaćanje pouzećem', 6 );
- }
- }
- }
- add_action( 'woocommerce_review_order_before_payment', 'mx_refresh_checkout_on_payment_method_change' );
- function mx_refresh_checkout_on_payment_method_change(){
- ?>
- <script type="text/javascript">
- (function($){
- $( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
- $('body').trigger('update_checkout');
- });
- })(jQuery);
- </script>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement