/*
Theme Name: Uncode Child
Description: Child theme for Uncode theme
Author: Undsgn™
Author URI: http://www.undsgn.com
Template: uncode
Version: 1.0.0
Text Domain: uncode
*/
/* Allarga il campo input del codice promozionale nel checkout */
.woocommerce-checkout #woocommerce-checkout-form-coupon .form-row-first,
.woocommerce-checkout .checkout_coupon.woocommerce-form-coupon .form-row-first {
    width: 60% !important;
    max-width: 50% !important;
    flex: 0 0 50% !important;
}

.woocommerce-checkout #woocommerce-checkout-form-coupon .form-row-last,
.woocommerce-checkout .checkout_coupon.woocommerce-form-coupon .form-row-last {
    width: 38% !important;
    max-width: 38% !important;
    flex: 0 0 38% !important;
    margin-left: 2% !important;
}

@media (max-width: 768px) {
    .woocommerce-checkout #woocommerce-checkout-form-coupon .form-row-first,
    .woocommerce-checkout .checkout_coupon.woocommerce-form-coupon .form-row-first,
    .woocommerce-checkout #woocommerce-checkout-form-coupon .form-row-last,
    .woocommerce-checkout .checkout_coupon.woocommerce-form-coupon .form-row-last {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        margin-left: 0 !important;
    }
}

/* Riduce il margine superiore del messaggio coupon nel checkout */
.woocommerce-checkout .woocommerce-info.wc-notice {
    margin-top: 10px !important;
    margin-bottom: 10px !important;
}

/* Riduce il margine superiore del form coupon */
.woocommerce-checkout .checkout_coupon.woocommerce-form-coupon,
.woocommerce-checkout #woocommerce-checkout-form-coupon {
    margin-top: 5px !important;
    padding-top: 10px !important;
}

/* Allarga il campo input del codice promozionale nel carrello */
.woocommerce-cart .coupon #coupon_code,
.woocommerce-cart-form .coupon #coupon_code {
    width: 60% !important;
    max-width: 60% !important;
    display: inline-block !important;
    vertical-align: top !important;
}

.woocommerce-cart .coupon .button,
.woocommerce-cart-form .coupon .button {
    width: 38% !important;
    max-width: 38% !important;
    margin-left: 2% !important;
    margin-top: 15px !important;
    display: inline-block !important;
    vertical-align: top !important;
}

@media (max-width: 768px) {
    .woocommerce-cart .coupon #coupon_code,
    .woocommerce-cart-form .coupon #coupon_code,
    .woocommerce-cart .coupon .button,
    .woocommerce-cart-form .coupon .button {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-top: 10px;
        display: block !important;
    }
}



// Imposta il peso di default a 0 per i nuovi prodotti
add_filter( 'default_hidden_meta_boxes', 'set_default_product_weight', 10, 2 );
function set_default_product_weight( $hidden, $screen ) {
    if ( isset($screen->id) && $screen->id === 'product' ) {
        if ( isset($_GET['post']) ) return $hidden;
        
        // Imposta il peso a 0
        add_filter( 'default_option_product_weight', function(){ return '0'; } );
    }
    return $hidden;
}



/* toglie i centesimi dai prezzi */
add_filter( 'woocommerce_get_price_including_tax', 'arrotonda_prezzo_finale', 10, 2 );
add_filter( 'woocommerce_get_price_excluding_tax', 'arrotonda_prezzo_finale', 10, 2 );

function arrotonda_prezzo_finale( $price, $product ) {
    return round( $price ); 
}
