<?php
/*
 Theme Name: Customizr Pro Child
 Theme URI: https://mikekonopka.com/
 Description: Child theme for Customizr Pro
 Author: Mike Konopka
 Template: customizr-pro
 Version: 1.0
*/

/* Import parent theme styles */


/* -------------------------------
   WooCommerce Checkout Enhancements
-----------------------------------*/

/**
 * Pre-fill the Billing State / County / Region field for front-end checkouts
 * Only affects new customer checkout sessions; does not touch existing orders
 */
add_filter( 'woocommerce_checkout_get_value', function( $value, $input ) {
    if( 'billing_state' === $input && empty($value) ) {
        $value = 'IL'; // Default state for new checkouts, change as needed
    }
    return $value;
}, 10, 2 );

/**
 * Set billing country to US internally for new admin orders
 * Does not affect existing orders or open invoices
 */
add_action( 'woocommerce_admin_order_data_after_billing_address', function( $order ) {
    if ( ! $order->get_id() ) { // Only new orders
        $order->set_billing_country( 'US' );
    }
});

/**
 * Visibly pre-select US in the Add New Order admin dropdown
 * Purely visual convenience, safe for open invoices
 */
add_action( 'admin_footer', function() {
    $screen = get_current_screen();
    if ( $screen && 'shop_order' === $screen->id && empty( $_GET['post'] ) ) {
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function($){
                $('#billing_country').val('US').trigger('change');
            });
        </script>
        <?php
    }
});

/**
 * Disable Woo guest email verification on the order-pay page
 * Keeps onboarding verification intact, removes payment friction
 */
add_filter( 'woocommerce_order_email_verification_required', function( $required, $order, $context ) {
    if ( 'order-pay' === $context ) {
        return false;
    }
    return $required;
}, 10, 3 );