/*
Theme Name: Flatsome Child
Description: This is a child theme for Flatsome Theme
Author: UX Themes
Template: flatsome
Version: 3.0
*/

/*************** ADD CUSTOM CSS HERE.   ***************/

/*
	Custom RTL css.
*/

@import url("../flatsome/rtl.css"); /* Load rtl.css */


.hurrytimer-campaign-4953 .hurrytimer-timer{
	
	 /*direction: rtl !important;
    flex-direction: row-reverse !important;  */
	 direction: rtl !important;
    display: flex !important;
    flex-direction: row-reverse !important;
    justify-content: center;
	
	
}


add_action('woocommerce_cart_calculate_fees', function($cart) {
    if (is_admin() && !defined('DOING_AJAX')) return;

    $discount_total = 0;

    foreach ($cart->get_cart() as $cart_item) {
        $product_id = $cart_item['product_id'];
        $quantity = $cart_item['quantity'];
        $line_total = $cart_item['line_total'];

        // مستقیم از post_meta بخونیم
        $carton_qty = intval(get_post_meta($product_id, 'carton_qty', true));
        $carton_discount = floatval(get_post_meta($product_id, 'carton_discount', true));

        if ($carton_qty > 0 && $carton_discount > 0 && $quantity >= $carton_qty) {
            // اینجا شرط مضربی بودن رو موقتا حذف کردیم
            $discount_total += $line_total * ($carton_discount / 100);
        }
    }

    if ($discount_total > 0) {
        $cart->add_fee(__('Carton Discount', 'textdomain'), -$discount_total);
    }
});
