Claim your freedom to choose the perfect partner for your multi-vendor journey.

FREEDOM25

Celebrate the festive season by giving your marketplace a powerful lift!

FESTIVE20

5.0.0
Something big is coming for marketplace admins… MultiVendorX 5.0 is almost here. Are you ready?
Be the first to explore all the game-changing features!
Power your marketplace dreams with unbeatable Black Friday deals!

MVXBLACK30

Supercharge your marketplace vision with unstoppable Cyber Monday deals!

MVXCYBER30

Holiday cheer, bigger savings
Take 25% off-because your marketplace deserves a gift too.

happyholiday

View Categories

Minimum order value

Using the below code the vendors can add minimum order value for their vendor stores. You need to add the code in the functions.php file of your current active theme –

add_action( 'mvx_vendor_add_store', 'add_min_amount_field', 99, 1 );
function add_min_amount_field( $vendor ) {
    $amount = get_user_meta($vendor->id, '_vendor_min_amount_of_order', true);
    ?>
    <div class="form-group">
        <label class="control-label col-sm-3 col-md-3"><?php _e('Minimium amount of order ', 'multivendorx'); ?></label>
        <div class="col-md-6 col-sm-9">
            <input class="no_input form-control" type="text" name="_vendor_min_amount_of_order" value="<?php echo esc_attr($amount); ?>"  placeholder="<?php _e('Enter your amount here', 'multivendorx'); ?>">
        </div> 
    </div>
    <?php
}

//save the field in database
add_action( 'mvx_save_custom_store', 'save_min_amount_field', 10, 1 );
function save_min_amount_field( $vendor_id ) {
    if ( isset($_POST['_vendor_min_amount_of_order']) ) {
        $min_amount_of_order = $_POST['_vendor_min_amount_of_order'];
        update_user_meta($vendor_id, '_vendor_min_amount_of_order', $min_amount_of_order);
    }
}

add_action( 'mvx_after_vendor_description', 'show_field', 10, 1 );
function show_field( $vendor_id ) {
    $min_amount_of_order = get_user_meta($vendor_id, '_vendor_min_amount_of_order', true);
    echo 'Minimum amount of order = '. $min_amount_of_order;
}
add_action( 'woocommerce_check_cart_items', 'check_minimum_cart_amount_of_each_vendor' );
function check_minimum_cart_amount_of_each_vendor() {
    if( is_cart() || is_checkout() ) {
        $items = WC()->cart->get_cart();
        $vendors = array();
        foreach ( $items as $item ) {
            $vendor = get_mvx_product_vendors( $item['product_id'] );
            if ( $vendor ) {
                $vendor_id = $vendor->id;
                if ( !empty($vendor_id) ) {
                    array_push($vendors, $vendor_id);
                }
            }
        }
        $all_vendors = array_unique(array_filter($vendors));
        foreach ( $all_vendors as $vendor_id ) {
            $vendor_total = get_subtotal($vendor_id);
            $min_amount_of_order = get_user_meta($vendor_id, '_vendor_min_amount_of_order', true);
            $vendor_info = get_mvx_vendor($vendor_id);
            if ( !empty($min_amount_of_order) ) {
                if ( intval($vendor_total) < intval($min_amount_of_order) ) {
                    wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout, for vendor %s."), $min_amount_of_order, $vendor_info->page_title ) . '<strong>', 'error' );
                    remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
                }
            }
        }
    }
}

function get_subtotal( $vendor_id ) {
    $subtotal = 0;
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
        $product_vendor_id = get_mvx_product_vendors( $cart_item['product_id'] )->id;
        if ( intval($vendor_id) != intval($product_vendor_id) ) {
            continue;
        }
        $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
        if ( get_option('woocommerce_tax_display_cart') === 'excl' ) {   
            $subtotal+=$cart_item['line_subtotal'];
        } else {
            $subtotal+=$cart_item['line_subtotal']+$cart_item['line_subtotal_tax'];
        }
    }
    return $subtotal;
}

Leave a Reply

Shopping Cart
Scroll to Top