/**
* Theme Name: Machic Child
* Description: This is a child theme of Machic, generated by Merlin WP.
* Author: <a href="http://themeforest.net/user/KlbTheme">KlbTheme (Sinan ISIK)</a>
* Template: machic
* Version: 1.5.7
*/
/* add_filter( 'woocommerce_available_payment_gateways', 'limit_cod_payment_gateway_by_amount' );

function limit_cod_payment_gateway_by_amount( $available_gateways ) {
    if ( is_admin() ) return $available_gateways;

    // Make sure WooCommerce cart exists
    if ( isset( WC()->cart ) ) {
        $total = WC()->cart->get_total( 'edit' ); // Get cart total (numeric)

        // Limit COD only for orders under 5000 PKR
        if ( $total > 5000 && isset( $available_gateways['cod'] ) ) {
            unset( $available_gateways['cod'] );
        }
    }

    return $available_gateways;
}

add_action( 'woocommerce_review_order_before_payment', function() {
    if ( WC()->cart && WC()->cart->get_total( 'edit' ) > 5000 ) {
        echo '<p style="color:red;">Cash on Delivery is only available for orders below 5000 PKR.</p>';
    }
}); */
