Home › Forums › WC Vendors Pro Support › A solution for per order shipping fee
NOTICE: We've Moved to a Ticket System for Support
As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system. This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.
For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.
If you are a WC Vendors Pro customer please open a support ticket here. If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.
The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.
Thank you to all of our customers!
- This topic has 17 replies, 6 voices, and was last updated 6 years, 10 months ago by Lauryn Wendus.
-
AuthorPosts
-
November 15, 2016 at 6:10 am #47690Marc BovetParticipant
Hello,
Here is my solution for the following scenario :
Vendor front end
Vendor can choose the minimum order amount.
Vendor can choose the shipping fees for an order.
Vendor can offer shipping when a certain amount order amount is reached.Customer
Vendor minimum amount not reached : a notice is displayed.
Free shipping is not reached : a notice with the remaining amount is displayed
Free shipping is reached : local pickup and wc vendors fees are hidden.First we need to create our custom fields for the vendor to be displayed on the front end
/** * @snippet Add custom shipping options for vendor * @author Marc Bovet * @testedwith WooCommerce 2.6.8 * @date 14.11.2016 */ function WC_Custom_Vendor_Shipping_Options( ){ //call WC_Custom_Vendor_Shipping_Options() in template "store-settings.php" if ( class_exists( 'WCVendors_Pro' ) ){ //Allow vendor to set a minimum order amount (0=> disabled.) $key = 'wcv_custom_settings_minimum_order_amount'; $value = get_user_meta( get_current_user_id(), $key, true ); WCVendors_Pro_Form_Helper::input( array( 'id' => $key, 'label' => __( 'Minimum order amount', 'wcvendors-pro' ), 'placeholder' => __( 'Orders below this amount are not allowed by the vendor', 'wcvendors-pro' ), 'desc_tip' => 'true', 'description' => __( 'Set the minimum oder amount', 'wcvendors-pro' ), 'type' => 'number', 'value' => $value, ) ); //Allow vendor to set shipping fees for an order $key = 'wcv_custom_settings_shipping_fees'; $value = get_user_meta( get_current_user_id(), $key, true ); WCVendors_Pro_Form_Helper::input( array( 'id' => $key, 'label' => __( 'Shipping fees', 'wcvendors-pro' ), 'placeholder' => __( 'Shipping fees set bythe vendor for 1 order', 'wcvendors-pro' ), 'desc_tip' => 'true', 'description' => __( 'Set shipping fees', 'wcvendors-pro' ), 'type' => 'number', 'value' => $value, ) ); //Allow vendor to set a minimal amount to get FREE shipping $key = 'wcv_custom_settings_free_shipping_amount'; $value = get_user_meta( get_current_user_id(), $key, true ); WCVendors_Pro_Form_Helper::input( array( 'id' => $key, 'label' => __( 'Free shipping starts', 'wcvendors-pro' ), 'placeholder' => __( 'Order amount to allow free shipping from the vendor', 'wcvendors-pro' ), 'desc_tip' => 'true', 'description' => __( 'Set the order amount for free shippping', 'wcvendors-pro' ), 'type' => 'number', 'value' => $value, ) ); } } //end function WC_Custom_Vendor_Shipping_Options
November 15, 2016 at 6:12 am #47691Marc BovetParticipantThen we need to inform our customer with messages
/** * @snippet WooCommerce: Define Minimum Order Amount & Show Errors * @sourcecode https://businessbloomer.com/?p=19947 * @author Rodolfo Melogli + Marc Bovet * @testedwith WooCommerce 2.5.2 * @date 14.11.2016 */ add_action( 'woocommerce_checkout_process', 'gastronomy_wc_minimum_order_amount' ); add_action( 'woocommerce_before_cart' , 'gastronomy_wc_minimum_order_amount' ); function gastronomy_wc_minimum_order_amount() { //if cart is empty, there is nothing to display. if ( WC()->cart->get_cart_contents_count() == 0 ) { return; } //TODO: //minimum order amount is not required for local pickup //return from here. // CAUTION // !!An order can only have products from 1 and only 1 vendor !! // get first product of the cart => then we can get vendor ID $items = WC()->cart->get_cart(); foreach($items as $item => $values) { $_product[] = $values['data']->post; } $vendor_id = get_post_field( 'post_author', $_product[0]->ID); //get minimum order amount $minimum = get_user_meta( $vendor_id, 'wcv_custom_settings_minimum_order_amount', true ); ; //Minimum order amount //Inform user that a minimum order amount is required. if ( WC()->cart->subtotal < $minimum ) { $text = sprintf( __('You must have a minimum order amount of %s to place your order. Your current order total is %s.') , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ); if( is_cart() ) { wc_print_notice($text,'error'); } else { wc_add_notice( $text,'error'); } return; //comment to display remaining amount to get free shipping. } //End minimum amount. //Show remaining amount to reach free shipping $minimum_amount_free_shipping = get_user_meta( $vendor_id, 'wcv_custom_settings_free_shipping_amount', true ); ; $delta = $minimum_amount_free_shipping - WC()->cart->subtotal; if ( $delta>0) { $text = sprintf( __('You only need to spend %s to get FREE shipping !') ,wc_price($delta) ); if( is_cart() ) { wc_print_notice($text,'notice'); } else { wc_add_notice($text,'notice'); } } //End amount free shipping }
November 15, 2016 at 6:13 am #47692Marc BovetParticipantEnable the free shipping fees when a certain amount is reached.
/** * @snippet WooCommerce : enable free shipping * @author Marc Bovet * @testedwith WooCommerce 2.6.8 * @date 15.11.2016 */ //Enable free shipping if minimum amount is reached. //Free shipping method need to be enabled from the backend, please read this link : https://docs.woocommerce.com/document/free-shipping/ // !! caution, see point 7 of weblink. amount value need to be set : N/A – Not available, Free Shipping is an option for all customers add_filter( 'woocommerce_shipping_free_shipping_is_available', 'custom_free_per_class' ); function custom_free_per_class( $is_available) { //if cart is empty, there is no free shipping available. if ( WC()->cart->get_cart_contents_count() == 0 ) { return false; } // CAUTION // !!An order can only have products from 1 and only 1 vendor !! // get first product of the cart => then we can get vendor ID $items = WC()->cart->get_cart(); foreach($items as $item => $values) { $_product[] = $values['data']->post; } $vendor_id = get_post_field( 'post_author', $_product[0]->ID); //get minimum order amount for free shipping $minimum = get_user_meta( $vendor_id, 'wcv_custom_settings_free_shipping_amount', true ); ; if ( WC()->cart->subtotal >= $minimum ) { return true; } else{ return false; } }//function
November 15, 2016 at 6:14 am #47693Marc BovetParticipantWhen free shipping is available, hide other methods.
/** * @snippet WooCommerce : hide all shipping methods when free is available. * @sourcecode https://gist.github.com/mikejolley/11171530 * @testedwith WooCommerce 2.6.8 * @date 15.11.2016 */ add_filter( 'woocommerce_package_rates', 'adjust_shipping_rates', 10, 2 ); /** * Hide shipping rates when free shipping is available * * @param array $rates Array of rates found for the package * @param array $package The package array/object being shipped * @return array of modified rates */ function adjust_shipping_rates( $rates, $package ) { // Only hide rates if free_shipping is present if ( isset( $rates['free_shipping:9'] ) ) { //use firebug to get the exact name for free shipping. // To unset a single rate/method, do the following. This example unsets flat_rate shipping unset( $rates['local_pickup:5'] ); unset( $rates['wcv_pro_vendor_shipping'] ); } else //adjust vendor shipping cost with required value. { // CAUTION // !!An order can only have products from 1 and only 1 vendor !! // get first product of the cart => then we can get vendor ID $items = WC()->cart->get_cart(); foreach($items as $item => $values) { $_product[] = $values['data']->post; } $vendor_id = get_post_field( 'post_author', $_product[0]->ID); //get shipping fees from vendor. $fee = get_user_meta( $vendor_id, 'wcv_custom_settings_shipping_fees', true ); ; //update shipping fees with vendor shipping fees. if(isset($rates['wcv_pro_vendor_shipping'])){ $rates['wcv_pro_vendor_shipping']->cost = $fee; } } return $rates; }
November 16, 2016 at 9:00 am #47798AnnaMember@marc.bovet
I haven’t tested this yet – but thank you so much for sharing this work, Marc. 🙂November 16, 2016 at 9:23 am #47805Marc BovetParticipant@fervous
you’re welcome.
I forgot to mention that WC Vendors needs to be configured like this in the backend :
1° WC vendor shipping needs to be activated
2° Shipping System : Flate Rate
3° Procut Cost Nationally set to a value > 0read carefully the comment in the provided code.
cheers,
November 16, 2016 at 6:56 pm #47855AnnaMemberUnderstood- thank you for the clarification. 🙂
November 29, 2016 at 3:22 am #48776JamieKeymasterHello,
As you have mentioned this code will only work if you have one product from one vendor in the cart. Do you prevent customers from adding more than one item in the cart?
Also version 1.4.0 has all this built in and working.
cheers,
Jamie.
November 29, 2016 at 9:06 am #48785AnnaMember@marc.bovet
While it is nice for members to share code– please understand that other users will have difficulty using this unless you format it into a gist; please visit github and get set up so you can share code in a more usable format.Also, if users d not read carefully they may not understand that this will only work if you have modified WC Vendors such that customers can only check out with ONE vendor in the cart. When you make your gist, please specify this very clearly so that users do not have negative results and confusion.
If I receive questions about this code, I will be tagging you to support the other members who attempt to use this and have questions.
Thank you!November 29, 2016 at 11:26 am #48831Marc BovetParticipantyes I prevent customers that they can only order products from 1 vendor (code is not provided), it can be done in the functions.php file.
A customer can have more than 1 product in the cart.
As there is no realease date for the 1.4 I have to find solution to progress….
@fervous
yes I’ve plannned to use ghist but no time for that right now.
I did not modified WC vendors but only used functions in my functions.php file.cheers,
November 30, 2016 at 12:00 am #48893Marc BovetParticipantthe gist can be found here:
https://gist.github.com/dummyphp/9d56499299e68e7f39472d60139fc79c
November 30, 2016 at 4:21 pm #48970AnnaMemberThanks, @marc.bovet
February 5, 2017 at 2:20 pm #55223JoeParticipantHi @Marc.Bovet
I have seen your code above. Do you have it available for ALL vendors, and not just limited to ONE vendor in the cart?
I would like to be able to use this, but allow customers to shop from any vendors at the same time.
Any help with this is very appreciated.
Many thanks
JoeFebruary 9, 2017 at 9:18 am #55581JoeParticipantHi @Marc.Bovet
I have seen your code above. Do you have it available for ALL vendors, and not just limited to ONE vendor in the cart?
I would like to be able to use this, but allow customers to shop from any vendors at the same time.
Any help with this is very appreciated.
Many thanks
JoeFebruary 9, 2017 at 9:42 am #55583Marc BovetParticipantHi Joe,
unfortunately not, but this could be adapted I think.
vendor 1 :
item 1.1
item 1.2
…vendor 2
item 2.1
item 2.2
…
Subtotal :shipping fees
flat rate vendor 1 : $$$
flat rate vendor 2 : $$$
Total shippings :You have to make trials and adapt the code.
HTH
cheers,April 30, 2017 at 2:31 am #63797Anas AkhtarParticipantHi @Marc.Bovet
I am able to successfully define minimum order amount & show errors for each vendor in cart. But for the ‘Enable the free shipping fees when a certain amount is reached’ and ‘When free shipping is available, hide other methods’ part I cant return two or more values for each vendor and the values that are displayed are always of the first product of cart vendor values.
Current Scenario:
For Example If I have two products in cart of two different vendors,vendor 1 :
item 1.1vendor 2 :
item 2.1The values of rates and enabling of free shipping is always looked out for the first item in the cart that would be vendor 1. If free shipping is enabled for vendor 1 then it also enables for vendor 2. If shipping rate for vendor 1 is 100 then it is for vendor 2.
For the enable free shipping part I want to return true or false for each vendor, and for the second part I want to return $rates for each vendor and display. Can anyone help me on how to return multiple values and then display with respect to each vendor their values ?
Regards,
AnasMay 2, 2017 at 12:25 pm #63998Anas AkhtarParticipantAny help ?
June 21, 2017 at 9:42 am #68632Lauryn WendusParticipantHi @ANAS-AKHTAR
Would you be willing to share how you did this for all vendors (more than one vendor per cart):
I am able to successfully define minimum order amount & show errors for each vendor in cart.
If I find a solution for the latter part of your post or connect with someone who can help I will certainly pass along to you!!
-
AuthorPosts
- The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.