/*
Theme Name:   Xstore child
Theme URI:    https://xstore.8theme.com
Description:  XStore is a multi-purpose theme that offers the ultimate WordPress and WooCommerce synergy, providing a comprehensive, all-in-one solution.
Author:       8theme
Author URI:   https://www.8theme.com
Template:     xstore
Version:      1.0
Text Domain:  xstore-child
Tags: e-commerce, two-columns, left-sidebar, right-sidebar, custom-background, custom-colors, custom-header, custom-menu, custom-logo, featured-images, full-width-template, threaded-comments, accessibility-ready, rtl-language-support, footer-widgets, sticky-post, theme-options, translation-ready, ecommerce, woocommerce, shop, elementor, business, corporate, blog, news, light, dark
*/// COD Extra Charges
add_action('woocommerce_cart_calculate_fees', 'cod_fee_with_ajax_fix', 20, 1);
function cod_fee_with_ajax_fix($cart) {

    if (is_admin() && !defined('DOING_AJAX')) return;
    if (did_action('woocommerce_cart_calculate_fees') >= 2) return;

    $chosen_payment = WC()->session->get('chosen_payment_method');

    if ($chosen_payment === 'cod') {
        $cart->add_fee(__('COD Handling Charges', 'woocommerce'), 40, false);
    }
}

/* FORCE refresh when payment changes */
add_action('wp_footer', 'cod_payment_refresh_script');
function cod_payment_refresh_script() {
    if (is_checkout()) :
    ?>
    <script type="text/javascript">
        jQuery(function($){
            $('form.checkout').on('change', 'input[name="payment_method"]', function(){
                $('body').trigger('update_checkout');
            });
        });
    </script>
    <?php
    endif;
}.woocommerce-review__verified {
    display: none !important;
}

