购物车消息适用于特定运输类别和Woocommerce中的最小购物车总数



我正在寻找以下解决方案:我想为购物车中具有特定运输类别的产品显示购物车消息,并且购物车小计低于 75 美元:

  • 运输等级:">贝佐格服务"。
  • 最小购物车数量:75。
  • 购物车消息: 订购 20,00 欧元以上,通过我们的送货服务将您的订单送货上门

任何帮助,不胜感激。

更新:这可以通过这个简单的自定义钩子函数轻松完成(代码被注释(:

add_action( 'woocommerce_before_calculate_totals', 'cart_items_shipping_class_message', 20, 1 );
function cart_items_shipping_class_message( $cart ){
if ( is_admin() && ! defined('DOING_AJAX') )
return;
## Your settings below ##
$shipping_class = 'bezorgservice'; // The targeted shipping class
$min_amout      = 75; // The minimal amount
$amout_incl_tax = 0; // Initializing variable
// Loop through cart items
foreach( $cart->get_cart() as $cart_item ){
// Targeting our defined shipping class only
if( $cart_item['data']->get_shipping_class() === $shipping_class ){
// Add each subtotal from our defined shipping class only
$amout_incl_tax += $cart_item['line_subtotal'] + $cart_item['line_subtotal_tax'];
}
}
// Display an error notice when quantity count is below the minimum defined on cart page only
if( $amout_incl_tax > 0 && $amout_incl_tax < $min_amout && is_cart() ){
wc_clear_notices(); // Clear all other notices
// Display our custom notice
wc_add_notice( sprintf( 'Order <strong>%s</strong> more to deliver your order at home with our delivery service.',
wc_price($min_amout - $amout_incl_tax) ), 'notice' );
}
}

代码进入函数.php活动子主题(或活动主题(的文件。经过测试并工作。

最新更新