Minimum car_totals message info for every vendor

Theme and Plugin Support

Minimum car_totals message info for every vendor Resolved

Viewing 16 reply threads
  • Author
    Posts
    • #91733
      domkopp29
      Participant

      hi, i need help.

      have different vendors with different prices to reach for free shipping. It works so far shows the minimum of prices if the customer reach all prices.
      Vendor 1 has: minimum 40€
      Vendor 2 has: minimum 50€

      My customer needs the message how much are the minimum of each vendor.

      i tried it with:
      // add minimum Text to cart
      add_filter( ‘woocommerce_no_shipping_available_html’, ‘my_custom_no_shipping_message’ );
      add_filter( ‘woocommerce_cart_no_shipping_available_html’, ‘my_custom_no_shipping_message’ );
      function my_custom_no_shipping_message( $message ) {

      $cart_amount = xxxxx?? Vendors minimum must be herexxxxxxx

      return __( ‘Mindestbestellsumme ‘.$cart_amount.’ist leider nicht erreicht. Bitte die Mindestbestellsumme pro Verkäufer beachten.’ );
      }

      please help. thanks

    • #91744

      @domkopp29, you need to use our filter to add a section for each vendor, where the vendor can add their own order amount.
      Then based on that settings, you have to do further code and calculate whether each vendor’s order is greater than equals to that order amount. Then only customers can proceed with this.

      We are already working on a developer doc on this. Once that is done, I will share that with you.

    • #91746
      domkopp29
      Participant

      Hi, thanks for the answer.
      i understand… which filter i need? how i get the vendor cart_amount? can you put from the developer some code here?
      thanks

    • #91748

      @domkopp29, we are working on the documentation right now, once that is done, I will share the documentation link with you.

    • #91749
      domkopp29
      Participant

      ok.. did i get it today? must launch my site.. very important..

    • #92264
      WCMp Admin
      Keymaster

      Add this code to the function.php of the current active theme :

      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_single_product_summary','single_product_summery', 35 );
      		/*set message on single product page*/ 
      		function single_product_summery() {
      		global $WCMp, $post;
      		$vendor_id = 0 ; $product_id = 0;
      		if( is_product() && $post && is_object( $post ) ) {
      			$product_id = $post->ID;
      			$vendor_id = $post->post_author;
      		}
      		if( !$product_id ) return;
      		if( !$vendor_id ) return;
      		$wcmp_min_order_amt = ( metadata_exists( 'user', $vendor_id, '_vendor_min_order_amount' ))? get_user_meta( $vendor_id, '_vendor_min_order_amount',true ) : '';
      		if( ! empty($wcmp_min_order_amt))
      			echo '<div class="clearfix"></div>'. __( 'Minimum order amount should be ', 'dc-woocommerce-multi-vendor' ) . ' ' . wc_price( $wcmp_min_order_amt ) .'<div class="clearfix"></div>';
      	}
      
      	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 ) && isset( $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
    • #92541
      luca-3088
      Participant

      i’m interested too in this feature. i paste this code in my functions.php file but is not seems to work. It appears a field in vendor admin area, but in the checkout is not calculate whether each vendor’s order is greater than equals.
      thanks for support
      Luca

    • #92583

      @luca-3088, can you share a temporary admin, ftp access so we can look into this.

      While sharing the access don’t forget to mark the response as private.

    • #92595
      luca-3088
      Participant

      Sorry but I still have project on my local environment

    • #92684
      luca-3088
      Participant

      any news?

    • #92741

      Can you share vendor access who has add their minimum cart amount?

    • #92743
      luca-3088
      Participant

      no i can’t, as i wrote you before i’m still working on local machine so i don’t have a public address. if you want i can share my git and db so you can test on your local machine as well. could it be ok? thanks

    • #92792
      Anonymous
      Inactive

      can you put from the developer some code here?

    • #92858
      luca-3088
      Participant
      
      /**
       * Set a minimum order amount for checkout for any shop
       */
      
      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_single_product_summary','single_product_summery', 35 );
      		/*set message on single product page*/ 
      		function single_product_summery() {
      		global $WCMp, $post;
      		$vendor_id = 0 ; $product_id = 0;
      		if( is_product() && $post && is_object( $post ) ) {
      			$product_id = $post->ID;
      			$vendor_id = $post->post_author;
      		}
      		if( !$product_id ) return;
      		if( !$vendor_id ) return;
      		$wcmp_min_order_amt = ( metadata_exists( 'user', $vendor_id, '_vendor_min_order_amount' ))? get_user_meta( $vendor_id, '_vendor_min_order_amount',true ) : '';
      		if( ! empty($wcmp_min_order_amt))
      			echo '<div class="minimum-order">'. __( 'Minimum order amount should be ', 'dc-woocommerce-multi-vendor' ) . ' ' . wc_price( $wcmp_min_order_amt ) .'</div>';
      	}
      
      	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 ) && isset( $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
    • #92859
      luca-3088
      Participant

      this is the code i paste in my child theme

    • #92887

      Hi, as you can see this code is working properly on our end: https://www.loom.com/share/701132dd4fd34d0eb8f7388a6e20cca6

      Can you share a video capture, where did you face an issue, so we can help you out.

    • #95035
      sreya
      Moderator

      I presume this issue has been resolved, so I am closing this thread.

      If you need any further help, please do open another thread.’

Viewing 16 reply threads

The topic ‘Minimum car_totals message info for every vendor’ is closed to new replies.

COVID-19 Outbreak: WCMp team is supporting business affected by coronavirus

Read the Message Buy at Slashed Price