Support » Plugin: WCFM Marketplace - Multivendor Marketplace for WooCommerce » Minimum order amount for each vendor

  • Resolved yodastudio

    (@yodastudio)


    Dear Sirs,

    I need to set a different minimum order amount for each store/vendor.
    I’m talking about value, not quantity.
    How can I do that? Is there any useful plugin able to do it?

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Hi,

    Please add this code to your site for the purpose –

    add_action( 'end_wcfm_vendor_settings', function( $vendor_id ) {
    	global $WCFM, $WCFMmp;
    	$wcfm_min_order_amt     = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    	?>
    	<!-- collapsible -->
    	<div class="page_collapsible" id="wcfm_settings_form_min_order_amount_head">
    		<label class="wcfmfa fa-cart-plus"></label>
    		<?php _e('Min Order Amount', 'wc-frontend-manager'); ?><span></span>
    	</div>
    	<div class="wcfm-container">
    		<div id="wcfm_settings_form_vendor_invoice_expander" class="wcfm-content">
    			<?php
    			$WCFM->wcfm_fields->wcfm_generate_form_field(  array(
    																														"_wcfm_min_order_amt" => array('label' => __('Minimum Amount', 'wc-frontend-manager'), 'type' => 'text', 'class' => 'wcfm-text wcfm_non_negative_input wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_min_order_amt ),
    																														) );
    	    ?>
    		</div>
    	</div>
    	<div class="wcfm_clearfix"></div>
    	<!-- end collapsible -->
    	<?php
    }, 500 );
    
    add_filter( 'wcfm_marketplace_settings_fields_general', function( $setting_fields, $vendor_id ) {
    	if( !wcfm_is_vendor() ) {
    		$wcfm_min_order_amt     = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    		$wcfm_min_order_amt_field = array(
    																		"_wcfm_min_order_amt" => array('label' => __('Minimum Amount', 'wc-frontend-manager'), 'type' => 'select', 'options' => array( '' => 0, '29' => '29', '39' => '39', '49' => '49', '99' => '99' ), 'class' => 'wcfm-select wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_min_order_amt ),
    																		);
    		$setting_fields = array_merge( $wcfm_min_order_amt_field, $setting_fields );
    	}
    	return $setting_fields;
    }, 50, 2 );
    
    add_action( 'woocommerce_single_product_summary', function() {
    	global $WCFM, $WCFMmp, $post;
    	
    	$vendor_id = 0;
    	$product_id = 0;
    	if( is_product() && $post && is_object( $post ) ) {
    		$product_id = $post->ID;
    		$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
    	}
    	if( !$product_id ) return;
    	if( !$WCFM->frontend->is_wcfm_needs_shipping( $product_id ) ) return;
    	if( !$vendor_id ) return;
    	$wcfm_min_order_amt     = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    	if( !$wcfm_min_order_amt ) return;
    	
    	echo '<div class="wcfm_clearfix"></div><div class="wcfmmp_shipment_processing_display">'. __( 'Minimum order amount should be ', 'wc-multivendor-marketplace' ) . ' ' . wc_price( $wcfm_min_order_amt ) .'</div><div class="wcfm_clearfix"></div>';
    }, 35 );
    
    add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
    	global $WCFM, $WCFMmp;
    	if( isset( $wcfm_settings_form['_wcfm_min_order_amt'] ) ) {
    		$wcfm_min_order_amt = $wcfm_settings_form['_wcfm_min_order_amt'];
    		update_user_meta( $vendor_id, '_wcfm_min_order_amt',  $wcfm_min_order_amt );
    	}
    }, 500, 2 );
    
    add_action( 'woocommerce_check_cart_items', function() {
    	global $WCFM, $WCFMmp;
    	$return = true;
    	if( is_cart() || is_checkout() ) {
    		$vendor_wise_cart_total = array();
    		
    		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
    		
    		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    			$cart_product_id = $cart_item['product_id'];
    			$cart_product = get_post( $cart_product_id );
    			if( !isset( $vendor_wise_cart_total[$cart_product->post_author] ) ) $vendor_wise_cart_total[$cart_product->post_author] = 0;
    			$vendor_wise_cart_total[$cart_product->post_author] += $cart_item['line_total'];
    		}
    		
    		if( !empty( $vendor_wise_cart_total ) ) {
    			foreach( $vendor_wise_cart_total as $vendor_id => $cart_total ) {
    				if( wcfm_is_vendor( $vendor_id ) ) {
    					if( !empty( $chosen_shipping_methods ) && isset( $chosen_shipping_methods[$vendor_id] ) ) {
    						//$ship_method_id = $chosen_shipping_methods[$vendor_id];
    						//$ship_id = explode( ":", $ship_method_id, 2 );
    						//$ship_id = $ship_id[0];
    						//if( $ship_id != 'local_pickup' ) {
    							$wcfm_min_order_amt     = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    							if( $wcfm_min_order_amt && ( $wcfm_min_order_amt > $cart_total ) ) {
    								wc_clear_notices();
    								$vendor_label = $WCFM->wcfm_vendor_support->wcfm_get_vendor_store_by_vendor( $vendor_id ) . ' ' . apply_filters( 'wcfm_sold_by_label', $vendor_id, __( 'Store', 'wc-frontend-manager' ) );
    								wc_add_notice( sprintf( __( "%s minimum order amount should be %s, please add few more items from this store!", "wc-frontend-manager" ), $vendor_label, wc_price( $wcfm_min_order_amt ) ), 'error' );
    								$return = false;
    								break;
    							}
    						//}
    					}
    				}
    			}
    		}
    	}
    	return $return;
    }, 1000 );

    Add this code to your child theme’s functions.phpIn case you do not have child theme then add code using this plugin – https://wordpress.org/plugins/code-snippets/

    Vendors may set minimum order amount from their setting panel – https://ibb.co/GQqY0Lv

    If condition not meet customer will see such a message under cart – https://ibb.co/vZqMbjr

    Thank You

    yodastudio

    (@yodastudio)

    It works, thanks a lot!

    Plugin Author WC Lovers

    (@wclovers)

    Great … you are welcome 🙂

    Hello there. my minimum order price does not work.

    Please HELP

    Lukas Prelovsky

    (@lukas-prelovsky)

    Hi, does not work.

    • This reply was modified 1 month ago by Lukas Prelovsky. Reason: allow notify me email

    the function does not work correctly because it accepts the entered price without VAT, and the displayed message is also without VAT price.

    Lukas Prelovsky

    (@lukas-prelovsky)

    I modified the code to display the price with VAT and to enter the price with VAT.

    The problem is that this snippet does not reflect the use of woocommerce coupons.

    This means that when a discount coupon is used and the order price is lower than the minimum value, the order will not pass.

    I would recommend adding a reflection on the use of woocommerce coupons, so that, for example, the minimum order amount is 40euros, and one will use a discount coupon to pass an order worth less than 40euros.

    Lukas Prelovsky

    (@lukas-prelovsky)

    Hi,

    This modified code adds support for:
    1. Price in admin settings with VAT and showing in error notice in VAT !
    2. Showing error notice in ceckout (minimum purcharse)
    3. Reflecting the use woo coupons (disable minimum purcharse in use coupon for concrete vendor and order continuation)

    
    /* View error notice when you click Proceed to cekout, just before checkout. Coupon acceptance - when using a coupon acceptance of an order for less than the minimum amount order allow to next step */
    add_action( 'woocommerce_cart_has_errors', 'bbloomer_add_jscript_checkout', 10);
     
    function bbloomer_add_jscript_checkout() {
    if( is_cart() || is_checkout() ) {
    $vendor_wise_cart_total = array();
    
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $cart_product_id = $cart_item['product_id'];
    $cart_product = get_post( $cart_product_id );
    if( !isset( $vendor_wise_cart_total[$cart_product->post_author] ) ) $vendor_wise_cart_total[$cart_product->post_author] = 0;
    $vendor_wise_cart_total[$cart_product->post_author] += round($cart_item['line_total']+$cart_item['line_tax'],2);
    }
    if( !empty( $vendor_wise_cart_total ) ) {
    foreach( $vendor_wise_cart_total as $vendor_id => $cart_total ) {
    if( wcfm_is_vendor( $vendor_id ) ) {
    $wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    if( $wcfm_min_order_amt && ( $wcfm_min_order_amt > $cart_total ) ) {
    $vendor_label = wcfm_get_vendor_store( $vendor_id ) . ' ' . apply_filters( 'wcfm_sold_by_label', $vendor_id, __( 'Store', 'wc-frontend-manager' ) );
    echo '<ul class="woocommerce-error" role="alert">
    			<li>
    			'.$vendor_label.'  minimálna hodnota objednávky u tohto predajcu musí byť '.wc_price( $wcfm_min_order_amt ).', pridajte niekoľko ďalších položiek z tohto obchodu! Aktuálna suma vložená od tohto predajcu je '.$cart_total.' € 		</li>
    	</ul>';
    }
    }
    }
    }
    
    	}
    }
    
    /* View cart notice for vendor minimum purchase over xyz amount + vendor shipping settings setting in administration */
    add_action( 'end_wcfm_vendor_settings', function( $vendor_id ) {
    global $WCFM, $WCFMmp;
    $wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    ?>
    <div class="page_collapsible" id="wcfm_settings_form_min_order_amount_head">
    <label class="wcfmfa fa-cart-plus"></label>
    <?php _e('Min Order Amount', 'wc-frontend-manager'); ?><span></span>
    </div>
    <div class="wcfm-container">
    <div id="wcfm_settings_form_vendor_invoice_expander" class="wcfm-content">
    <?php
    $WCFM->wcfm_fields->wcfm_generate_form_field( array(
    "_wcfm_min_order_amt" => array('label' => __('Minimum Amount', 'wc-frontend-manager'), 'type' => 'number', 'class' => 'wcfm-text wcfm_non_negative_input wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_min_order_amt ),
    ) );
    ?>
    </div>
    </div>
    <div class="wcfm_clearfix"></div>
    <?php
    }, 500 );
    add_filter( 'wcfm_marketplace_settings_fields_general', function( $setting_fields, $vendor_id ) {
    if( !wcfm_is_vendor() ) {
    $wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    $wcfm_min_order_amt_field = array(
    "_wcfm_min_order_amt" => array('label' => __('Minimum Amount', 'wc-frontend-manager'), 'type' => 'number', 'class' => 'wcfm-text wcfm_non_negative_input wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_min_order_amt ),
    );
    $setting_fields = array_merge( $wcfm_min_order_amt_field, $setting_fields );
    }
    return $setting_fields;
    }, 50, 2 );
    add_action( 'woocommerce_single_product_summary', function() {
    global $WCFM, $WCFMmp, $post;
    $vendor_id = 0;
    $product_id = 0;
    if( is_product() && $post && is_object( $post ) ) {
    $product_id = $post->ID;
    }
    if( !$product_id ) return;
    $vendor_id = wcfm_get_vendor_id_by_post( $product_id );
    if( !$vendor_id ) return;
    $wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    if( !$wcfm_min_order_amt ) return;
    echo '<div class="wcfm_clearfix"></div><div class="wcfmmp_shipment_processing_display">'. __( 'Minimum order amount should be ', 'wc-multivendor-marketplace' ) . ' ' . wc_price( $wcfm_min_order_amt ) .'</div><div class="wcfm_clearfix"></div>';
    }, 35 );
    add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
    global $WCFM, $WCFMmp;
    if( isset( $wcfm_settings_form['_wcfm_min_order_amt'] ) ) {
    $wcfm_min_order_amt = $wcfm_settings_form['_wcfm_min_order_amt'];
    update_user_meta( $vendor_id, '_wcfm_min_order_amt', $wcfm_min_order_amt );
    }
    }, 500, 2 );
    add_action( 'woocommerce_check_cart_items', function() {
    global $WCFM, $WCFMmp;
    $return = true;
    if( is_cart() || is_checkout() ) {
    $vendor_wise_cart_total = array();
    $applied_coupons = WC()->cart->get_applied_coupons();
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $cart_product_id = $cart_item['product_id'];
    $cart_product = get_post( $cart_product_id );
    if( !isset( $vendor_wise_cart_total[$cart_product->post_author] ) ) $vendor_wise_cart_total[$cart_product->post_author] = 0;
    //echo $test = $cart_item['line_total']+$cart_item['line_tax'];
    $vendor_wise_cart_total[$cart_product->post_author] += round($cart_item['line_total']+$cart_item['line_tax'],2);
    }
    if( !empty( $vendor_wise_cart_total ) ) {
    foreach( $vendor_wise_cart_total as $vendor_id => $cart_total ) {
    if( wcfm_is_vendor( $vendor_id ) && empty($applied_coupons) ) {
    $wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
    if( $wcfm_min_order_amt && ( $wcfm_min_order_amt > $cart_total ) ) {
    wc_clear_notices();
    $vendor_label = wcfm_get_vendor_store( $vendor_id ) . ' ' . apply_filters( 'wcfm_sold_by_label', $vendor_id, __( 'Store', 'wc-frontend-manager' ) );
    wc_add_notice( sprintf( __( "%s minimálna hodnota objednávky u tohto predajcu musí byť %s, pridajte niekoľko ďalších položiek z tohto obchodu! Aktuálna suma vložená od tohto predajcu je ".$cart_total." € ", "wc-frontend-manager" ), $vendor_label, wc_price( $wcfm_min_order_amt ) ), 'error' );
    $return = false;
    break;
    }
    }
    }
    }
    }
    return $return;
    }, 1000 );
    
    

    I believe it will help many people. 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.