【发布时间】:2023-01-09 14:23:58
【问题描述】:
由于 DHL 插件计算运费,添加到购物车速度很慢。 我们在主题 function.php 中添加了以下代码行
/*
Remove recalculation of the shipping cost when Add-to-Cart. This prevents slow add-to-cart.
*/
function filter_need_shipping ($val) {
$prevent_after_add = WC()->cart->prevent_recalc_on_add_to_cart;
return $val && !$prevent_after_add;
}
add_filter( 'woocommerce_cart_needs_shipping', 'filter_need_shipping' );
function mark_cart_not_to_recalc ($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
WC()->cart->prevent_recalc_on_add_to_cart = true;
}
add_action('woocommerce_add_to_cart', 'mark_cart_not_to_recalc', 10, 6);
添加到购物车现在很快,但只要 WooCommerce 插件处于活动状态,以下磨损就会显示在仪表板中。
Warning: Attempt to read property "prevent_recalc_on_add_to_cart" on null in /home/website/public_html/wp-content/themes/woodmart-child/functions.php on line 568
您的帮助将不胜感激
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce