У меня есть магазин на базе Woocommerce. Я использовал Эту ссылку , чтобы изменить цены продукта вариантов с помощью крючка от LoicTheAzte c.
Это работает отлично, но я обнаружил, что когда пользователь открывает страницу продукта или любую страницу, включая цену, он будет выдавать ошибку (хранится в файле журнала ошибок, и пользователи не могут этого видеть).
Означает, что ошибка отображается в режиме отладки, а также сохраняется в файле error_log в Root.
Ошибка: [25-фев-2020 11:12:57 ...] PHP Предупреждение: не числовое значение c, обнаруженное в /home/website/public_html/wp-content/themes/name/functions.php on line 1147
Line 1147: return $price * get_price_multiplier();
Этот хук используется:
// Utility function to change the prices with a multiplier (number)
function get_price_multiplier() {
return 1.2; // x2 for testing
}
// Simple, grouped and external products
add_filter('woocommerce_product_get_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_get_regular_price', 'custom_price', 99, 2 );
// Variations
add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'custom_price', 99, 2 );
function custom_price( $price, $product ) {
return $price * get_price_multiplier();
}
// Variable (price range)
add_filter('woocommerce_variation_prices_price', 'custom_variable_price', 99, 3 );
add_filter('woocommerce_variation_prices_regular_price', 'custom_variable_price', 99, 3 );
function custom_variable_price( $price, $variation, $product ) {
// Delete product cached price (if needed)
// wc_delete_product_transients($variation->get_id());
return $price * get_price_multiplier();
}
// Handling price caching (see explanations at the end)
add_filter( 'woocommerce_get_variation_prices_hash', 'add_price_multiplier_to_variation_prices_hash', 99, 1 );
function add_price_multiplier_to_variation_prices_hash( $hash ) {
$hash[] = get_price_multiplier();
return $hash;
}
- Woocommerce версия: 3.9.2
- PHP версия: 7.2