Я использую перехватчики для настройки переменных цен на товары.
Однако этот ответ, похоже, не работает для Woocommerce 3.3.5.
Я использую следующее (из предыдущего поста) в своем файле function.php:
add_filter('woocommerce_variation_prices_price', 'custom_variation_price', 99, 3 );
add_filter('woocommerce_variation_prices_regular_price', 'custom_variation_price', 99, 3 );
function custom_variation_price( $price, $variation, $product ) {
// Delete product cached price (if needed)
wc_delete_product_transients($variation->get_id());
return $price * 3; // X2 for testing
}
На странице продукта в диапазоне цен для вариантов продукта указаны правильные цены (исходная цена*3), но когда я выбираю варианты, цена, указанная для варианта, не фильтруется. Я что-то упустил?
РЕДАКТИРОВАТЬ: У меня был немного другой расчет цен для простых продуктов и для их разновидностей. В итоге у меня получилось 3 функции:
// Simple
add_filter('woocommerce_product_get_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_get_regular_price', 'custom_price', 99, 2 );
// Variable
add_filter('woocommerce_product_variation_get_regular_price', 'custom_price_2', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'custom_price_2' , 99, 2 );
// Variations (of a variable product)
add_filter('woocommerce_variation_prices_price', 'custom_variation_price', 99, 3 );
add_filter('woocommerce_variation_prices_regular_price', 'custom_variation_price', 99, 3 );
function custom_price( $price, $product ) {
// Delete product cached price (if needed)
wc_delete_product_transients($product->get_id());
return $price * 3; // X3 for testing
}
function custom_price_2( $price, $product ) {
// Delete product cached price (if needed)
wc_delete_product_transients($product->get_id());
return $price * 2; // X2 for testing
}
function custom_variation_price( $price, $variation, $product ) {
// Delete product cached price (if needed)
wc_delete_product_transients($variation->get_id());
return $price * 2; // X2 for testing
}
Подробнее здесь: https://stackoverflow.com/questions/499 ... mmerce-3-3
Изменение цен на варианты продуктов с помощью хука в WooCommerce 3.3 ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как правильно искать варианты продуктов по тегам продуктов в WooCommerce?
Anonymous » » в форуме Php - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-