[ad_1]
Asked
Viewed
3 times
I created ACF text field “akcni_cena” which a use as a special price and it is something like the second sale price. I need to this acf field to recalculate when currency change. It doesn’ work now.
The other prices like wc_get_price_excluding_tax or wc_get_price_including_tax are normally recalculating when currency change.
<?php
global $product;
$price_excl_tax = wc_get_price_excluding_tax( $product ); // price without VAT
$price_incl_tax = wc_get_price_including_tax( $product ); // price with VAT
$symbol = get_woocommerce_currency_symbol();
$regular_price = $product->get_regular_price();
$akcni_nabidka = get_field('akcni_nabidka');
$akcni_nabidka_on = $akcni_nabidka == true;
$akcni_cena = get_field('akcni_cena');
$today = date("Y-m-d H:i:s");
$today_time = strtotime($today);
$end_time = strtotime(get_field('ukonceni_akcni_nabidky'));
if( $product->is_type('simple') || $product->is_type('external') || $product->is_type('grouped') ) {
if ($akcni_cena && $akcni_nabidka_on && $end_time > $today_time) {
if( $product->is_on_sale() ) {
/* Přeškrtnutá zlevněná cena */
echo '<div class="strikethrough"> <span class="regprice">' . number_format($regular_price) . $symbol . '</span>' . number_format($price_incl_tax) . ' ' . $symbol . ' <span class="vat">s DPH</span> <br>' .
number_format($price_excl_tax) . ' ' . $symbol . ' <span class="vat">bez DPH</span> </div>';
} else {
/* Přeškrtnutá normální cena */
echo '<div class="strikethrough"> </span>' . wc_price($price_incl_tax) . ' ' . $symbol . ' <span class="vat">s DPH</span> <br>' .
wc_price($price_excl_tax) . ' ' . $symbol . ' <span class="vat">bez DPH</span> </div>';
}
/* Akční cena */
echo 'Akční cena: ' . number_format($akcni_cena) . ' ' . $symbol . ' <span class="vat">s DPH</span>' ;
} else {
if( $product->is_on_sale() ) {
/* Zlevněná cena */
echo '<span class="regprice strikethrough">' . number_format($regular_price) . ' ' . $symbol . '<span class="vat"> s DPH</span> </span>' . number_format($price_incl_tax) . ' ' . $symbol . ' <span class="vat">s DPH</span> <br>' .
number_format($price_excl_tax) . ' ' . $symbol . ' <span class="vat">bez DPH</span>';
} else {
/* Normální cena */
echo number_format($price_incl_tax) . ' ' . $symbol . ' <span class="vat">s DPH</span> <br>' .
number_format($price_excl_tax) . ' ' . $symbol . ' <span class="vat">bez DPH</span>';
}
}
}elseif($product->is_type('variable')) {
$product_variations = $product->get_available_variations();
$variation_product_id = $product_variations[0]['variation_id'];
$variation_product = new WC_Product_Variation( $variation_product_id );
$variation_product_price = $variation_product ->regular_price;
$variation_prodct_sale_price = $variation_product ->sale_price;
$variable_price = $product->get_price();
if ($akcni_cena && $akcni_nabidka_on && $end_time > $today_time) {
if( $product->is_on_sale() ) {
/* Přeškrtnutá zlevněná cena */
echo '<span class="regprice strikethrough">' . number_format($variation_product_price) . ' ' . $symbol . '</span> <br> <span>' . number_format($variation_prodct_sale_price) . ' ' . $symbol . '</span>';
} else {
/* Přeškrtnutá normální cena */
echo '<div class="regprice strikethrough">' . number_format( $variation_product_price) . ' ' . $symbol . '</div>';
}
/* Akční cena */
echo 'Akční cena: ' . number_format($akcni_cena) . ' ' . $symbol . '<span class="vat"> s DPH</span>' ;
}else {
if( $product->is_on_sale() ) {
/* Zlevněná cena */
echo '<span class="regprice strikethrough">' . number_format($variation_product_price) . ' ' . $symbol . '</span> <br> <span>' . number_format($variation_prodct_sale_price) . ' ' . $symbol . '</span>';
} else {
/* Normální cena */
echo '<span>' . number_format($variation_product_price) . ' ' . $symbol . '</span>';
}
}
}
?>
lang-php
[ad_2]