Answer the question
In order to leave comments, you need to log in
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 );
}
Answer the question
In order to leave comments, you need to log in
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>';
}
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 questionAsk a Question
731 491 924 answers to any question