Я пытаюсь выяснить, как показать все варианты цен в виде текста на одной странице продукта.
например, если у продукта 5 разных цен, 1 – 500, 2 – 900, 3 – 2100, 4–2500, 5–3000
Я хочу, чтобы это отображалось в тексте на всех страницах продукта.
вот так:
ВАРИАЦИИ
1 – 500
2 – 900.
сейчас я делаю это вручную, записываю их все, чтобы у людей не было необходимости прокрутить раскрывающееся меню вниз, чтобы узнать цены, но я хочу, чтобы это делалось автоматически при изменении цен, чтобы мне не приходилось каждый раз менять этот текст. я пробовал разные крючки, но не нашел подходящего.
я пробовал этот, но не могу крючок сработать и показать его на странице продукта
add_filter( 'woocommerce_get_price_html', 'custom_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_price_format', 10, 2 );
function custom_price_format( $price, $product ) {
// 1. Variable products
if( $product->is_type('variable') ){
// Searching for the default variation
$default_attributes = $product->get_default_attributes();
// Loop through available variations
foreach($product->get_available_variations() as $variation){
$found = true; // Initializing
// Loop through variation attributes
foreach( $variation['attributes'] as $key => $value ){
$taxonomy = str_replace( 'attribute_', '', $key );
// Searching for a matching variation as default
if( isset($default_attributes[$taxonomy]) && $default_attributes[$taxonomy] != $value ){
$found = false;
break;
}
}
// When it's found we set it and we stop the main loop
if( $found ) {
$default_variaton = $variation;
break;
} // If not we continue
else {
continue;
}
}
// Get the default variation prices or if not set the variable product min prices
$regular_price = isset($default_variaton) ? $default_variaton['display_price']: $product->get_variation_regular_price( 'min', true );
$sale_price = isset($default_variaton) ? $default_variaton['display_regular_price']: $product->get_variation_sale_price( 'min', true );
}
// 2. Other products types
else {
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
}
// Formatting the price
if ( $regular_price !== $sale_price && $product->is_on_sale()) {
// Percentage calculation and text
$percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ).'%';
$percentage_txt = __(' Save', 'woocommerce' ).' '.$percentage;
$price = '' . wc_price($regular_price) . ' ' . wc_price($sale_price) . $percentage_txt . '';
}
return $price;
}
Подробнее здесь: https://stackoverflow.com/questions/704 ... price-list
Прайс-лист на варианты продуктов Woocommerce ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как правильно искать варианты продуктов по тегам продуктов в WooCommerce?
Anonymous » » в форуме Php - 0 Ответы
- 13 Просмотры
-
Последнее сообщение Anonymous
-