G
G
Genri_Rus2019-12-25 17:49:52
WordPress
Genri_Rus, 2019-12-25 17:49:52

What hook is responsible for editing the price of the variation near the select?

The problem arose in this, after I hid all the prices

add_filter( 'woocommerce_get_price_html', hide_all_wc_prices', 10, 2);
function hide_all_wc_prices( $price, $product ) {
  return '';
}

add_filter( 'woocommerce_get_price_html', custom_price_html', 10, 2 );
function custom_price_html( $price, $product ) {
  $regular_price 			 = method_exists( $product, 'get_regular_price' ) ? $product->get_regular_price() : $product->regular_price;
  $sale_price 			 = method_exists( $product, 'get_sale_price' ) ? $product->get_sale_price() : $product->sale_price;
  $regular_variation_price = method_exists( $product, 'get_variation_price' ) ? $product->get_variation_price() : $product->regular_price;
  
  if ( !$product->get_sale_price() ) {
    if (!$regular_price) {
      $regular_price = $regular_variation_price;
      
      $product->get_price() ? $price .= '<span class="price-original">' . number_format($regular_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span>' : $price .= '<span class="product-original">Цена не указана</span>';
    } 
  } else {
    $price .= '<span class="price-sale">' . number_format($sale_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span><span class="product-sale">' . number_format($regular_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span>';  
  }
  
  return apply_filters( 'woocommerce_get_price', $price );
}

Now I can't display the variable price. 5e0375fd53796711099593.png
Can I display this price using some kind of hook?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Genri_Rus, 2019-12-25
@Genri_Rus

For those who are interested, everything should have worked, I just forgot to specify this check:
And instead:

if ( !$product->get_sale_price() ) {
    if (!$regular_price) {
      $regular_price = $regular_variation_price;
      
      $product->get_price() ? $price .= '<span class="price-original">' . number_format($regular_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span>' : $price .= '<span class="product-original">Цена не указана</span>';
    }

You need to do this:
if ( !$product->get_sale_price() ) {
      $product->get_price() ? $price .= '<span class="price-original">' . number_format($regular_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span>' : $price .= '<span class="product-original">Цена не указана</span>';
} else {
    $price .= '<span class="price-sale">' . number_format($sale_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span><span class="product-sale">' . number_format($regular_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span>';  
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question