我正在寻找以下解决方案:我想显示购物车中有特定运费等级的产品的购物车消息以及当购物车小计低于75美元时:
感谢任何帮助。
答案 0 :(得分:1)
更新:这可以通过此简单的自定义挂钩函数(带有注释的代码)轻松完成:
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' );
}
}
代码进入活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。