Minimum order amount per vendor

WCMp Core

Resolved
Viewing 4 reply threads
  • Author
    Posts
    • #123649
      raoul
      Participant

      Hi, I have some vendors who have a minimum order amount. Therefore I’d like to set a minimum order amount for each vendor.

      I have been using the snippets here https://multivendorx.com/tech-blog/set-minimum-order-amount-per-vendor/. The first two snippets work. I can allow vendors to set their minimum order amount through the vendor dashboard. I can also see that it is saved after a vendor submits their minimum order amount. So far, all good!

      However, the final snippet which displays a message to the customer on cart and checkout page does not work. I have tested this many times and even though I set a minimum order amount of 25, I am able to checkout an order under the minimum amount and no message is displayed. Without this message, customers are easily able to purchase under the minimum amount.

      Do you know why the final snippet doesn’t work? Is this snippet up to date https://multivendorx.com/tech-blog/set-minimum-order-amount-per-vendor/?

      Thanks

    • #123728

      Hi,

      Kindly use below code and check :-

      add_action( 'wcmp_after_shop_front', 'extra_setting_fields' );
          /*form for vendor dashboard set min order field*/
          function extra_setting_fields() { 
              $vendor_id = get_current_vendor_id();
              $wcmp_min_order_amt = ( metadata_exists( 'user', $vendor_id, '_vendor_min_order_amount' ))? get_user_meta( $vendor_id, '_vendor_min_order_amount', true ):'';
              ?>
                  <div class="panel panel-default pannel-outer-heading">
                      <div class="panel-heading">
                          <h3><?php _e('Vendor Options', 'dc-woocommerce-multi-vendor'); ?></h3>
                      </div>
                      <div class="panel-body panel-content-padding form-horizontal">
                          <div class="wcmp_media_block">
                              <div class="form-group">
                                  <label class="control-label col-sm-3 col-md-3"><?php _e('Set minimum buy amount', 'dc-woocommerce-multi-vendor'); ?></label>
                                  <div class="col-md-6 col-sm-9">
                                      <input class="form-control" type="number"  name="set_min_order" value="<?php echo $wcmp_min_order_amt ; ?>">
                                  </div>  
                              </div>
                          </div>
                      </div>
                  </div>
              <?php 
          }
      
          add_action('before_wcmp_vendor_dashboard', 'save_vendor_dashboard_data_min_order_amount');
          /*save vendor dashboard data into user_meta*/
          function save_vendor_dashboard_data_min_order_amount(){
              global $WCMp;
              $vendor_id = get_current_vendor_id();
              if($_SERVER['REQUEST_METHOD'] == 'POST') {
                  if($WCMp->endpoints->get_current_endpoint() == 'storefront') {
                     if($_POST['set_min_order']){
                          $min_order_amount = absint($_POST['set_min_order']);
                         ( metadata_exists( 'user', $vendor_id, '_vendor_min_order_amount' ))? update_user_meta( $vendor_id, '_vendor_min_order_amount', $min_order_amount ):add_user_meta( $vendor_id, '_vendor_min_order_amount', $min_order_amount );  
                     }
                  }
              }
          }
      
          add_action( 'woocommerce_check_cart_items', 'check_vendor_per_product', 500 );
          /*set message on cart page*/
          function check_vendor_per_product(){
              global $WCMp;
              $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( is_user_wcmp_vendor( $vendor_id ) ) {
                              if( !empty( $chosen_shipping_methods ) && $chosen_shipping_methods[$vendor_id] ) {
                                  $wcmp_min_order_amt = ( metadata_exists( 'user', $vendor_id, '_vendor_min_order_amount' ))? get_user_meta( $vendor_id, '_vendor_min_order_amount',true ) : 0;
                                  if( $wcmp_min_order_amt && ( $wcmp_min_order_amt > $cart_total ) ) {
                                      wc_clear_notices();
                                      /*user cart message*/
                                      wc_add_notice( sprintf( __( "Minimum order amount should be %s, please add few more items from this store!", "dc-woocommerce-multi-vendor" ),  wc_price( $wcmp_min_order_amt ) ), 'error' );
                                      $return = false;
                                      break;
                                  }
                              }
                          }
                      }
                  }
              }
              return $return;
          }
      Copy

      Regards,

    • #123779
      raoul
      Participant

      Hey, thanks for the code snippet.

      Unfortunately I have the same issue. I am able to set a minimum order amount via the vendor dashboard. However this doesn’t seem to be enforced. I am able to purchase under the minimum order amount for that vendor and there is no message on the cart or checkout page telling me I need to buy above the minimum order amount.

      Can you think of any reason why this last snippet would not work? I really appreciate your help on this as my largest vendor will only launch once we can set minimum order amount – thank you so much!

    • #123829

      Hi @raoul, please make sure that the vendor has the capability to ship their product, i.e. you have added “vendor shipping” method with that shipping zone.
      Only then this will work.

    • #127061

      We haven’t heard back from you for a while. We hope this issue is fixed, so we are closing this now.
      If you need any further help, please do open another thread.

Viewing 4 reply threads

The topic ‘Minimum order amount per vendor’ is closed to new replies.