@Genri_Rus

Какой хук отвечает за редактирование цены вариации возле select?

Проблема возникла вот в чем, после того как я скрыл все цены
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 );
}

Теперь у меня не выводится вариативная цена 5e0375fd53796711099593.png
Может можно эту цену вывести с помощью какого-то хука ?
  • Вопрос задан
  • 213 просмотров
Пригласить эксперта
Ответы на вопрос 1
@Genri_Rus Автор вопроса
Кому интересно, то все должно было работать, просто я забыл указать вот такую проверку:

$regular_price 	= $product->is_type('variable') ? $product->get_variation_regular_price( 'min', true ) : ( method_exists( $product, 'get_regular_price' ) ? $product->get_regular_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>';
    }

Нужно сделать так:
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>';  
  }
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы