Juškus gallery

El. parduotuvei pardavinėjančiai paveikslus įvestas euro ir lito rodymas tik pasirinkus lietuvių kalbai.

Programinis kodas:

//modified by webai.lt
if(WPLANG == "lt_LT" || ICL_LANGUAGE_CODE == "lt"){

$currency = get_woocommerce_currency(); // parduotuvės valiuta
$euro = " Lt."; // euro simbolis su non-breaking space
$rate = 3.45280; // santykis

$dec_sep = wp_specialchars_decode(stripslashes(get_option('woocommerce_price_decimal_sep')),ENT_QUOTES);
$tho_sep = wp_specialchars_decode(stripslashes(get_option('woocommerce_price_thousand_sep')),ENT_QUOTES);
$num_dec = absint(get_option('woocommerce_price_num_decimals'));

// filters
add_filter('woocommerce_variation_price_html', 'convert_variation_price_html', 10, 2);
add_filter('woocommerce_variation_sale_price_html', 'convert_variation_sale_price_html', 10, 2);
add_filter('woocommerce_get_price_html','convert_get_price_html', 10, 2);
add_filter('woocommerce_cart_item_price','convert_cart_item_price', 10, 3);
add_filter('woocommerce_cart_item_subtotal','convert_cart_item_subtotal', 10, 3);
add_filter('woocommerce_cart_subtotal', 'convert_cart_subtotal', 10, 3);
add_filter('woocommerce_cart_total', 'convert_cart_total', 10,1);
//add_filter('woocommerce_cart_total_ex_tax', 'convert_cart_total_ex_tax', 10,1);
add_filter('woocommerce_cart_shipping_method_full_label', 'convert_cart_shipping_method_full_label', 10, 2);
add_filter('woocommerce_cart_totals_fee_html', 'convert_cart_totals_fee_html', 10, 2);
add_filter('woocommerce_cart_totals_coupon_html', 'convert_cart_totals_coupon_html', 10, 2);
add_filter('woocommerce_order_formatted_line_subtotal', 'convert_order_formatted_line_subtotal', 10, 3);
add_filter('woocommerce_get_order_item_totals', 'convert_get_order_item_totals', 10, 2);
add_filter('woocommerce_get_formatted_order_total', 'convert_get_formatted_order_total', 10, 2);
add_filter( 'woocommerce_price_trim_zeros', function() { return false; } );
add_filter( 'woocommerce_price_trim_zeros', '__return_false' );

// funkcijos
function convert_variation_price_html($price, $this) {

        return "<span class=\"amount\">".strip_tags($price)." (".wc_format_localized_price(number_format(strip_tags(wc_format_decimal($price)) / $GLOBALS['rate'],$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS["euro"].")</span>";
}

function convert_variation_sale_price_html($price, $this) {
        $prices = explode($GLOBALS['currency'], strip_tags($price));
        return "<del>".convert_variation_price_html($prices[0].$GLOBALS['currency'], $this)."</del><ins>".convert_variation_price_html($prices[1].$GLOBALS['currency'], $this)."</ins>";
}

function convert_get_price_html($price, $id) {

        /* $product = get_product($id);
        $prices = explode("&ndash;", strip_tags($price));
        $price = str_replace(',', '', $price); */

        $product = new WC_Product($id);
        $get_if_reduced_price = $product->get_price();

        if ($get_if_reduced_price) {
                return $price." <span class='to_ltl'>(".wc_format_localized_price(number_format(wc_format_decimal($get_if_reduced_price) * $GLOBALS['rate'],$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")</span>";
      /*  } else if (count($prices) == 2) {
                return $price." <span class='to_ltl'>(".wc_format_localized_price(number_format(wc_format_decimal($prices[0]) * $GLOBALS['rate'],$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro']."&ndash;".wc_format_localized_price(number_format(wc_format_decimal($prices[1])* $GLOBALS['rate'],$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")</span>";
       */
         } else { return $price; }
}

function convert_cart_item_price($price, $cart_item, $cart_item_key) {
        $eurPrice = strip_tags($price);
         $eurPrice = str_replace(',', '', $eurPrice);
        return $price." (".wc_format_localized_price(number_format(round(wc_format_decimal($eurPrice) * $GLOBALS['rate'],1),$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")";
}

function convert_cart_item_subtotal($price, $cart_item, $cart_item_key) {
        $eurPrice = strip_tags($price);
        $eurPrice = str_replace(',', '', $eurPrice);
        $eurPrice = $eurPrice/$cart_item["quantity"];

        $eurPrice = round($eurPrice * $GLOBALS['rate'],1);

        $eurPrice = $eurPrice*$cart_item["quantity"];

        return $price." (".wc_format_localized_price(number_format(wc_format_decimal($eurPrice),$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")";
}

function convert_cart_subtotal($cart_subtotal, $compound, $this) {
        $contents = WC()->cart->cart_contents;
        $eurSubtotal = 0;
        foreach ($contents as $value) {
                $id = strlen($value['variation_id']) > 0 ? $value['variation_id'] : $value['product_id'];
                $product = new WC_Product($id);
                $price = $product->get_price();
                $eurPrice = round($price * $GLOBALS['rate'],1);
                $eurSubtotal += $eurPrice*$value["quantity"];
        }
        return $cart_subtotal." (".wc_format_localized_price(number_format(wc_format_decimal($eurSubtotal),$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")";
}

function convert_cart_total($price){
        $contents = WC()->cart->cart_contents;
        $eurSubtotal = 0;
        foreach ($contents as $value) {
                $id = strlen($value['variation_id']) > 0 ? $value['variation_id'] : $value['product_id'];
                $product = new WC_Product($id);
                $cost = $product->get_price();
                $eurPrice = round($cost * $GLOBALS['rate'],1);
                $eurSubtotal += $eurPrice*$value["quantity"];
        }
        $shipping = WC()->shipping->shipping_total;
        $fees = WC()->cart->fee_total;
        $discount = wc_format_decimal(WC()->cart->get_total_discount());
        $eurDiscount = round($discount * $GLOBALS['rate'],1);
        $eurShipping = round($shipping * $GLOBALS['rate'],1);
        $eurFees = round($fees * $GLOBALS['rate'],1);
        $eurSubtotal += $eurShipping + $eurFees - $eurDiscount;

        return wc_format_localized_price($price)." (".wc_format_localized_price(number_format(wc_format_decimal($eurSubtotal),$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")";
}

/*function convert_cart_total_ex_tax($price){

}*/

function convert_cart_shipping_method_full_label($label, $method) {
        global $woocommerce;
        if ($method->cost > 0) {
                $labels = explode("<span class=\"amount\">", $label);
                $label = $labels[0];
                $label .= "<span class=\"amount\">".$labels[1]."</span>";
                $label .= "<span style=\"font-weight: normal;font-size: 13px;color: #444;\"> (".wc_format_localized_price(number_format(round(wc_format_decimal($labels[1]) * $GLOBALS['rate'], 1), $GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")</span>";
        }
        if ($method->id == "distance_shipping_method") {
                $class = new WC_Distance_Shipping_Method();
                $distance = $class->get_distance($woocommerce->customer->get_shipping_address(),$woocommerce->customer->get_shipping_city());
                $label .= ' ('.$distance[0].' km) '.$distance[1];
        }
        return $label;
}

function convert_cart_totals_fee_html($cart_totals_fee_html, $fee) {
        return $cart_totals_fee_html." (".wc_format_localized_price(number_format(round(wc_format_decimal($fee->amount) * $GLOBALS['rate'],1),$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")";
}

function convert_cart_totals_coupon_html($value, $coupon) {
        $values = explode("</span>", $value);
        if (count($values) == 2) {
                $value = $values[0]." (";
                $value .= wc_format_localized_price(number_format(round(wc_format_decimal(strip_tags($values[0])) * $GLOBALS['rate'],1), 2)).$GLOBALS["euro"];
                $value .= ")</span>".$values[1];
        }
        return $value;
}

function convert_order_formatted_line_subtotal($subtotal, $item, $this) {
        $eurSub = 0;
        $id = strlen($item['variation_id']) > 0 ? $item['variation_id'] : $item['product_id'];
        $product = new WC_Product($id);
        $price = $product->get_price();
        $eurPrice = round($price * $GLOBALS['rate'],1);
        $eurSub += $eurPrice*$item["qty"];
        return $subtotal." (".wc_format_localized_price(number_format(wc_format_decimal($eurSub),$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")";

}

function convert_get_order_item_totals($total_rows, $this) {
        $order = new WC_Order($this);
        $items = $order->get_items();
        $eurSub = 0;
        foreach ($items as $item) {
                $id = strlen($item['variation_id']) > 0 ? $item['variation_id'] : $item['product_id'];
                $product = new WC_Product($id);
                $price = $product->get_price();
                $eurPrice = round($price * $GLOBALS['rate'],1);
                $eurSub += $eurPrice*$item["qty"];
        }
        array_splice($total_rows, 0, 1, array("cart_subtotal" => array("label" => $total_rows["cart_subtotal"]["label"], "value" => "<span class=\"amount\">".strip_tags($total_rows["cart_subtotal"]["value"])." (".wc_format_localized_price(number_format($eurSub,$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")</span>")));
        foreach ($total_rows as &$row) {
                $curpos = strpos($row["value"],$GLOBALS['currency']);
                $eurpos = strpos($row["value"],$GLOBALS['euro']);
                $len = strlen($GLOBALS['currency']);
                $last = $curpos+$len;
                if ($curpos !== false && $eurpos === false) {
                        $row["value"] = substr_replace($row["value"], " (".wc_format_localized_price(number_format(round(wc_format_decimal(strip_tags($row["value"])) * $GLOBALS['rate'],1),$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")", $last, 0);
                }
        }
        return $total_rows;
}

function convert_get_formatted_order_total($formatted_total, $this) {
        $order = new WC_Order($this);
        $items = $order->get_items();
        $eurSubtotal = 0; $fees = 0;
        foreach ($items as $item) {
                $id = strlen($item['variation_id']) > 0 ? $item['variation_id'] : $item['product_id'];
                $product = new WC_Product($id);
                $price = $product->get_price();
                $eurPrice = round($price * $GLOBALS['rate'],1);
                $eurSubtotal += $eurPrice*$item["qty"];
        }
        $shipping = $order->get_total_shipping();
        foreach ($order->get_fees() as $item) {
                $fees += $item['line_total'];
        }
        $discount = $order->get_order_discount();
        $eurDiscount = round($discount * $GLOBALS['rate'],1);
        $eurShipping = round($shipping * $GLOBALS['rate'],1);
        $eurFees = round($fees * $GLOBALS['rate'],1);
        $eurSubtotal += $eurShipping + $eurFees - $eurDiscount;

        $formatted_total = $formatted_total . " (".wc_format_localized_price(number_format(wc_format_decimal($eurSubtotal),$GLOBALS['num_dec'],$GLOBALS['dec_sep'],$GLOBALS['tho_sep'])).$GLOBALS['euro'].")";
        return $formatted_total;
}


} else { }