最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Different Minimum Order Amounts based on Shipping Zone

programmeradmin1浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

I have 3 zones setup in woocommerce shipping. I am simply trying to create a rule where if a certain zone is set for shipping, a minimum order amount is different. For 2 of my zones the minimum order amount is $49.99

This works fine.

For one of the zones I'd like it to be a minimum order of $99.99

This is not working. I can't seem to get it to work. Help appreciated.

// -----------------------------------------
// MINIMUM CART AMOUNT FOR CHECKOUT

add_action( 'woocommerce_check_cart_items', 'required_min_cart_subtotal_amount' );
function required_min_cart_subtotal_amount() {
    $zone = WC_Shipping_Zones::get_zone_by( 'zone_id', 3 );
    // Only run in the Cart or Checkout pages
    if( is_cart() || is_checkout() && $zone !== 3 ) {

        // HERE Set minimum cart total amount
        $min_total = 49.99;

        // Total (before taxes and shipping charges)
        $total = WC()->cart->subtotal;

        // Add an error notice is cart total is less than the minimum required
        if( $total <= $min_total  ) {
            // Display an error message
            wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($min_total) ) . '<strong>', 'error' );
        }
    }
    elseif( is_cart() || is_checkout() && $zone == 3 ) {

        // HERE Set minimum cart total amount
        $min_total = 99.99;

        // Total (before taxes and shipping charges)
        $total = WC()->cart->subtotal;

        // Add an error notice is cart total is less than the minimum required
        if( $total <= $min_total  ) {
            // Display an error message
            wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($min_total) ) . '<strong>', 'error' );
        }
    }
}
发布评论

评论列表(0)

  1. 暂无评论