By the way, I tried this below code to achieve my client ‘s requirements.
ON JS FILE:
jQuery(document).ready(function () {
jQuery(‘#billing_country’).change(function () {
var billingcountry = $(this).val();
var billing_country = jQuery(‘#billing_country’).val();
var data = {
action: ‘woocommerce_apply_billing_country’,
security: wc_checkout_params.apply_billing_country_nonce,
billing_country: billing_country
};
jQuery.ajax({
type: ‘POST’,
url: wc_checkout_params.ajax_url,
data: data,
success: function (code) {
alert (code +”Code”);
},
dataType: ‘html’
});
return false;
});
});
ON FUNCTIONS.PHP FILE:
wp_enqueue_script(‘billing_country’, get_template_directory_uri() . ‘/js/billing_country_call.js’, array(‘jquery’));
wp_localize_script(‘billing_country’, ‘wc_checkout_params’, array(‘ajaxurl’ => admin_url(‘admin-ajax.php’)));
add_action(‘woocommerce_apply_billing_country’, ‘calculate’, 10);
add_action(‘wp_ajax_nopriv_woocommerce_apply_district’, ‘calculate’, 10);
function calculate() {
if (isset($_POST[‘billing_country’])) {
global $woocommerce ;
$order_shipping_total = 0;
$billing_country = $_POST[‘billing_country’];
if ( $billing_country == “US” ) {
$order_shipping_total = 25;
} else {
$order_shipping_total = 50;
}
session_start();
$_SESSION[‘val’] = $order_shipping_total;
}
}
add_action(‘woocommerce_cart_calculate_fees’, ‘wpi_add_ship_fee’);
function wpi_add_ship_fee() {
@session_start();
$customshipcost = $_SESSION[‘val’];
WC()->cart->add_fee(‘Shipping :’, $customshipcost );
}
it returns zero right under subtotal on checkout page.
any help will be highly appreciated.
Best regards,
Imran