Fórum Root.cz
Hlavní témata => Vývoj => Téma založeno: Wangarad 25. 05. 2022, 10:24:18
-
Zdravicko.
Chcel som vo woocomerce pridat funkciu ktora by zobrazovala cenu s DPH a nasledne bez DPH na stranke produktu
Pouzil som toto
add_filter('woocommerce_get_price_html', 'edit_price_display', 10, 2);
function edit_price_display($price, $instance) {
global $product;
if(is_singular('product')) {
$price = $product->price;
$price_incl_tax = $price + round($price * ( 21 / 100 ), 3);
$price_incl_tax = number_format($price_incl_tax, 3, ",", ".");
$price = number_format($price, 3, ",", ".");
$display_price = '<span class="price">';
$display_price .= '<span class="amount">' . $price_incl_tax .' € <small class="woocommerce-price-suffix"> s DPH</small></span>';
$display_price .= '<br>';
$display_price .= '<span class="amount" style = "font-size: 13px; color: #767676;"> ' . $price .'€<small class="woocommerce-price-suffix" style = "font-size: 13px; color: #767676;"> bez DPH</small></span>';
$display_price .= '</span>';
echo $display_price;
} else {
echo $price;
}
}
Funguje to skvelo ale narazil som na problem ze pokial je to variable produkt tak mi to zobrazuje okrem tejto ceny aj ceny vsetkych variacii. Ako to oklamat resp. upravit tak aby to neovplyvnovalo aj ceny pre variabilne produkty?
-
Takze som to upravil a uz to viac menej funguje ako ma jediny detail a sice podstatny je v tom ze mi to nechce aktualizovat cenu vzhladom na variantu produktu.
add_filter('woocommerce_get_price_html', 'edit_price_display', 10, 2);
function edit_price_display($price, $instance) {
global $product;
if(is_a( $product, 'WC_Product_Variable' )) {
$prefix = sprintf('%s: ', __('Od', 'wcvp_range'));
$postfix = ' s DPH';
$postfix_without = ' bez DPH';
$wcv_reg_min_price = $product->get_variation_regular_price( 'min', true );
$wcv_min_sale_price = $product->get_variation_sale_price( 'min', true );
$wcv_max_price = $product->get_variation_price( 'max', true );
$wcv_min_price = $product->get_variation_price( 'min', true );
$float_value_of_var = floatval($wcv_min_price);
$price_incl_tax = $float_value_of_var + round($float_value_of_var * ( 20 / 100 ), 3);
$price_incl_tax = number_format($price_incl_tax, 3, ",", ".");
$wcv_price = ( $wcv_min_sale_price == $wcv_reg_min_price ) ?
wc_price( $wcv_reg_min_price ) :
'<del>' . wc_price( $wcv_reg_min_price ) . '</del>' . '<ins>' . wc_price( $wcv_min_sale_price ) . '</ins>';
return ( $wcv_min_price == $wcv_max_price )?
$wcv_price :
sprintf('%s%s%s%s%s%s', $prefix, $price_incl_tax, $postfix,'</br>', $price_incl_tax, $postfix_without);
}else{
$price = $product->price;
$price_incl_tax = $price + round($price * ( 20 / 100 ), 3);
$price_incl_tax = number_format($price_incl_tax, 3, ",", ".");
$price = number_format($price, 3, ",", ".");
$display_price = '<span class="price">';
$display_price .= '<span class="amount">' . $price_incl_tax .' € <small class="woocommerce-price-suffix"> s DPH</small></span>';
$display_price .= '<br>';
$display_price .= '<span class="amount" style = "font-size: 13px; color: #767676;"> ' . $price .'€<small class="woocommerce-price-suffix" style = "font-size: 13px; color: #767676;"> bez DPH</small></span>';
$display_price .= '</span>';
echo $display_price;
}
}