Advertisement
Fany_VanDaal

Cena s a bez DPH

Nov 24th, 2022 (edited)
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. add_filter('woocommerce_get_price_html', 'zobrazeni_ceny_s_a_bez_dph', 100, 2 );
  2. function zobrazeni_ceny_s_a_bez_dph( $price_html, $product ) {
  3.     global $woocommerce_loop;
  4.  
  5.     // Pouze na stránkách jednotlivých produktů (a ne na loopu)
  6.     if( isset($woocommerce_loop['total']) && $woocommerce_loop['total'] == 0
  7.     && isset($woocommerce_loop['total']) && empty($woocommerce_loop['name']) ) {
  8.  
  9.         // Pro jednoduché a variabilní produkty
  10.         if( $product->is_type('simple') || $product->is_type('variation') ) {
  11.             // Když e ve slevě
  12.             if( $product->is_on_sale() ) {
  13.                 $regular_price_incl_tax = wc_get_price_including_tax( $product, array( 'price' => $product->get_regular_price() ) );
  14.                 $price_incl_tax_html    = wc_format_sale_price( $regular_price_incl_tax, wc_get_price_including_tax( $product ) );
  15.                 $regular_price_excl_tax = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_regular_price() ) );
  16.                 $price_excl_tax_html    = wc_format_sale_price( $regular_price_excl_tax, wc_get_price_excluding_tax( $product ) );
  17.             }
  18.             // Když není ve slevě
  19.             else {
  20.                 $price_incl_tax_html = wc_price( wc_get_price_including_tax( $product ) );
  21.                 $price_excl_tax_html = wc_price( wc_get_price_excluding_tax( $product ) );
  22.             }
  23.         }
  24.         // Variabilní produkty
  25.         elseif( $product->is_type('variable') ) {
  26.             $prices = $product->get_variation_prices( true );
  27.  
  28.             if ( ! empty( $prices['price'] ) ) {
  29.                 $act_keys = array_keys($prices['price']);
  30.                 $reg_keys = array_keys($prices['regular_price']);
  31.  
  32.                 $min_price_incl_tax = wc_get_price_including_tax( wc_get_product(reset($act_keys)));
  33.                 $max_price_incl_tax = wc_get_price_including_tax( wc_get_product(end($act_keys)));
  34.  
  35.                 $min_price_excl_tax = wc_get_price_excluding_tax( wc_get_product(reset($act_keys)));
  36.                 $max_price_excl_tax = wc_get_price_excluding_tax( wc_get_product(end($act_keys)));
  37.  
  38.                 $min_reg_price_jncl_tax = wc_get_price_including_tax( wc_get_product(reset($reg_keys)));
  39.                 $max_reg_price_incl_tax = wc_get_price_including_tax( wc_get_product(end($reg_keys)));
  40.  
  41.                 $min_reg_price_excl_tax = wc_get_price_excluding_tax( wc_get_product(reset($reg_keys)));
  42.                 $max_reg_price_excl_tax = wc_get_price_excluding_tax( wc_get_product(end($reg_keys)));
  43.  
  44.                 if ( $min_price_excl_tax !== $max_price_excl_tax ) {
  45.                     $price_incl_tax_html = wc_format_price_range( $min_price_incl_tax, $max_reg_price_incl_tax );
  46.                     $price_excl_tax_html = wc_format_price_range( $min_price_excl_tax, $max_reg_price_excl_tax );
  47.                 }
  48.                 elseif ( $product->is_on_sale() && $min_reg_price_excl_tax === $max_reg_price_excl_tax ) {
  49.                     $price_incl_tax_html = wc_format_sale_price( wc_price( $max_reg_price_incl_tax ), wc_price( $min_price_incl_tax ) );
  50.                     $price_excl_tax_html = wc_format_sale_price( wc_price( $max_reg_price_excl_tax ), wc_price( $min_price_excl_tax ) );
  51.                 }
  52.                 else {
  53.                     $price_incl_tax_html = wc_price( $min_price_incl_tax );
  54.                     $price_excl_tax_html = wc_price( $min_price_excl_tax );
  55.                 }
  56.             }
  57.         }
  58.         if ( isset($price_incl_tax_html) && isset($price_excl_tax_html) ) {
  59.             $price_html  = '<bdi><span class="cena_vcetne_dph">' . $price_incl_tax_html . ' s DPH</span><bdi><br>';
  60.             $price_html .= '<bdi><span class="cena_bez_dph" style="font-size:0.5em">' . $price_excl_tax_html . ' bez DPH</span><bdi><br>';
  61.             $price_html .= $product->get_price_suffix();
  62.         }
  63.     }
  64.     return $price_html;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement