Created
June 7, 2019 08:27
-
-
Save blivic/634f273fb17a45e16b2c2dae57ec31b7 to your computer and use it in GitHub Desktop.
Adding a fee if chosen payment method is COD
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( 'woocommerce_cart_calculate_fees', 'mx_add_cod_fee', 20, 1 ); | |
function mx_add_cod_fee( $cart ) { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
$your_payment_id = 'cod'; // Metoda plaćanja | |
$fee_amount = 6; // Naknada | |
$chosen_payment_method_id = WC()->session->get( 'chosen_payment_method' ); | |
if ( $chosen_payment_method_id == $your_payment_id ) { | |
$fee_text = __( "Troškovi plaćanja pouzećem", "woocommerce" ); | |
$cart->add_fee( $fee_text, $fee_amount, false ); // Promijeniti u true ako trebaš obračun/prikaz poreza na naknadu | |
} | |
} | |
add_action( 'wp_footer', 'refresh_checkout_script' ); | |
function refresh_checkout_script() { | |
if( is_checkout() && ! is_wc_endpoint_url('order-received') ) : | |
?> | |
<script type="text/javascript"> | |
jQuery(function($){ | |
$('form.woocommerce-checkout').on( 'change', 'input[name="payment_method"]', function(){ | |
$('body').trigger('update_checkout'); | |
}); | |
}) | |
</script> | |
<?php | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment