Activate/Deactivate COD by vendors when desired.

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WCFM – Feature Request Activate/Deactivate COD by vendors when desired.

Viewing 22 reply threads
  • Author
    Posts
    • #32242
      d-n-13
      Participant

      Hi good wclovers team,

      I have tested the new feature “Reverse Withdrawal” and it works flawless ! Very well done wclovers !

      Although this awesome feature is implemented, we cannot really use COD in most cases, currently WCFM Marketplace expects you to have shipping model as one of the following :-

      1- Shipping by Admin only (COD per gateway can be done using 3rd party plugins such as Booster).
      2- Shipping by Vendors only (All Vendors provide COD).
      3- Shipping by Vendors only (All Vendors DON’T provide COD).
      4- (1)+(2).
      5- (1)+(3)

      Note : (2)+(3) cannot work together atm.

      As you can see, Marketplace like mine where vendors do all the shipping by themselves won’t work well with COD + Reverse Withdrawal because I need to decide to accept only vendors who provide COD or accept vendors who don’t provide COD.

      Now in what cases vendors provide or don’t provide COD ?

      A – Some vendors will have to use 3rd party shipping companies such as FedEx and of course they don’t provide COD.
      B – Some vendors will have to use 3rd party shipping companies such as local shipping companies and they provide COD services.
      C – If vendor do the shipping himself or individual partners then he can do COD.

      As you can see, it’s hard to control when Vendors provide COD or Not.

      Why this is an issue ?

      If admin activate COD as payment method, then it will always be available at checkout, even for vendors who don’t provide COD, and they will have to cancel / re-apply order, it will cause bad experience for both Customers and Vendors.

      Summery : Vendors need to have the ability to activate/deactivate COD by shipping methods or products. Also COD should be off by default and turned on by vendors when desired.

      Kind Regards,
      Khalid

    • #36594
      WCFM Forum
      Keymaster

      Hi,

      Sorry for delayed update on this.

      Tell me one thing, are using any plugin (Booster) for controlling payment gateway options at checkout as cart products?

      Suppose, a vendor does not support COD then this pay option should be hidden from checkout if this vendor’s product on cart, is this happen to your site?

      Well, we can add an option at vendor level – whether “Reverse Withdrawal” will for him or not! Hope this will solve your issues quite a bit.

      Please know me your thoughts!

      Thank You

    • #36871
      d-n-13
      Participant

      Hi,

      I don’t understand exactly what you mean,

      Regarding Booster these are the options available : https://www.dropbox.com/s/rk5j9x326esorxd/payment%20gateway.JPG?dl=0

      I am not sure how it is possible to integrate this with wcfm.

      I want a simple checkbox option for vendors to show or hide COD, some vendors can some vendors cannot do COD.

      WCFM Marketplace is so awesome with COD it has Reverse Withdrawal and many other features supports COD, but it only works if all vendors do COD.

      Thank You

    • #36919
      Mustafa
      Participant

      +1

    • #36951
      WCFM Forum
      Keymaster

      HI,

      “Regarding Booster these are the options available” – As I know this option comes with Product, right?

      So, do you want to have this in WCFM product manager?

      Thank You

    • #36960
      d-n-13
      Participant

      Hi,

      You mean in each product, a Vendor can set if it has COD or Not ? that would be a reasonable solution.

      Thank You

    • #36962
      d-n-13
      Participant

      Side Note,

      It is better to associate COD with shipping if possible, example here : https://www.dropbox.com/s/4rnd3r4tc78em8l/shipping%2034.JPG?dl=0

      Why is this better ? because if vendor wanna ship to different city or country he don’t want COD to be enabled.

      I don’t know how easy or hard to do this in shipping level, but if it can be it would be better I think.

    • #37183
      WCFM Forum
      Keymaster

      Hi,

      “It is better to associate COD with shipping if possible”
      – With shipping method this will not work! WC has no such dependency.
      Booster even allow only payment gateway specific shipping – https://booster.io/features/woocommerce-payment-gateways-by-shipping/
      But reverse option not possible!

      We will implement this for product/vendor specific.
      Hope you are using this – https://booster.io/features/woocommerce-payment-gateways-per-product-or-category/
      Or some other plugin for the purpose?

      Thank You

    • #37225
      d-n-13
      Participant

      Hi,


      With shipping method this will not work! WC has no such dependency.
      Booster even allow only payment gateway specific shipping – https://booster.io/features/woocommerce-payment-gateways-by-shipping/
      But reverse option not possible!

      How about you give me a filter to add new shipping methods “Flat Rate with COD”, “Free shipping with COD” and I add them to https://booster.io/features/woocommerce-payment-gateways-by-shipping/ ???

      “We will implement this for product/vendor specific.”

      You mean a vendor can add COD or remove COD while managing/editing the products ? it will be perfect

    • #38478
      WCFM Forum
      Keymaster

      HI,

      “You mean a vendor can add COD or remove COD while managing/editing the products ? ”

      – Yeah, this is possible to implement. Vendor will set whether they allow COD or not from their setting panel.
      If COD not allowed by a vendor then if customer add his product in cart then COD option will not available under checkout for that order pay option.

      Thank You

    • #38495
      d-n-13
      Participant

      Hi,

      If possible to make it disabled by default then vendors can toggle them on when needed it would be cool.

      Thank You

    • #38507
      WCFM Forum
      Keymaster

      Hi,

      Yeah possible. but how you want to make this enable – Vendor wise or Product specific?

      Thank You

    • #38528
      d-n-13
      Participant

      Hi,

      Both are fine, I prefer vendor wise, 1 time setting. starting as disabled.

      Thank You

    • #38542
      WCFM Forum
      Keymaster

      OK, I will give you code for this.

      Thank You

    • #38543
      WCFM Forum
      Keymaster

      Hi,

      Here is your code for the purpose –

      // Payment Gateway Control
      add_filter( 'woocommerce_available_payment_gateways', function( $available_gateways ) {
      	global $WCFM;
      	if( isset( $available_gateways['cod'] ) ) {
      		$cod_available = false;
      		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
      			$cod_available = false;
      			$_product     = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
      
      			if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
      				$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $_product->get_id() );
      				if( !$vendor_id || !wcfm_is_vendor( $vendor_id ) ) continue;
      				$vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
      				if( !$vendor_data ) $vendor_data = array();
      				$is_cod_enabled = isset( $vendor_data['payment']['wcfm_cod_enabled'] ) ? 'yes' : 'no' ;
      				if( $is_cod_enabled == 'yes' ) {
      					$cod_available = true;
      				}
      			}
      		}
      		
      		// Unset COD
      		if( !$cod_available )
      			unset( $available_gateways['cod'] );
      	}
      	
      	return $available_gateways;
      }, 200 );
      
      // Vendor Setting
      add_filter( 'wcfm_marketplace_settings_fields_billing', function( $vendor_billing_fileds, $vendor_id ) {
      	$vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
      	if( !$vendor_data ) $vendor_data = array();
      	$is_cod_enabled = isset( $vendor_data['payment']['wcfm_cod_enabled'] ) ? 'yes' : 'no' ;
      	
      	$vendor_wcfm_cod_enabled_fileds = array(
      													'wcfm_cod_enabled' => array('label' => __('COD Enable for Checkout', 'wc-frontend-manager'), 'name' => 'payment[wcfm_cod_enabled]', 'type' => 'checkbox', 'class' => 'wcfm-checkbox wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele checkbox_title', 'value' => 'yes', 'dfvalue' => $is_cod_enabled ),
      													);
      	$vendor_billing_fileds = array_merge( $vendor_wcfm_cod_enabled_fileds, $vendor_billing_fileds );
      	return $vendor_billing_fileds;
      }, 50, 2);

      There is a setting option for enable COD for any vendor – https://ibb.co/zVh4c0M

      Thank You

    • #39020
      d-n-13
      Guest

      Hello,

      I’ve tested out, it is working 90% prefect,

      the problem is if there are 2 products one of them with COD then it apply COD to both, is it possible to make it the opposite way ? if one of them with no COD then both/all don’t offer COD in the same order ?

    • #39023
      WCFM Forum
      Keymaster

      Hi,

      “the problem is if there are 2 products one of them with COD then it apply COD to both, is it possible to make it the opposite way ? if one of them with no COD then both/all don’t offer COD in the same order ?”
      – Really! As i have written code in a way -> if cart has two products from two different vendor but only one allow COD then COD will not available for pay option. Is this not working for you?

      Well, I have tweak this code a bit, please use this ->

      // Payment Gateway Control
      add_filter( 'woocommerce_available_payment_gateways', function( $available_gateways ) {
      	global $WCFM;
      	if( isset( $available_gateways['cod'] ) ) {
      		$cod_available = false;
      		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
      			$cod_available = false;
      			$_product     = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
      
      			if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
      				$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $_product->get_id() );
      				if( !$vendor_id || !wcfm_is_vendor( $vendor_id ) ) continue;
      				$vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
      				if( !$vendor_data ) $vendor_data = array();
      				$is_cod_enabled = isset( $vendor_data['payment']['wcfm_cod_enabled'] ) ? 'yes' : 'no' ;
      				if( $is_cod_enabled == 'yes' ) {
      					$cod_available = true;
      				} else {
                                              break;
                                      }
      			}
      		}
      		
      		// Unset COD
      		if( !$cod_available )
      			unset( $available_gateways['cod'] );
      	}
      	
      	return $available_gateways;
      }, 200 );
      
      // Vendor Setting
      add_filter( 'wcfm_marketplace_settings_fields_billing', function( $vendor_billing_fileds, $vendor_id ) {
      	$vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
      	if( !$vendor_data ) $vendor_data = array();
      	$is_cod_enabled = isset( $vendor_data['payment']['wcfm_cod_enabled'] ) ? 'yes' : 'no' ;
      	
      	$vendor_wcfm_cod_enabled_fileds = array(
      													'wcfm_cod_enabled' => array('label' => __('COD Enable for Checkout', 'wc-frontend-manager'), 'name' => 'payment[wcfm_cod_enabled]', 'type' => 'checkbox', 'class' => 'wcfm-checkbox wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele checkbox_title', 'value' => 'yes', 'dfvalue' => $is_cod_enabled ),
      													);
      	$vendor_billing_fileds = array_merge( $vendor_wcfm_cod_enabled_fileds, $vendor_billing_fileds );
      	return $vendor_billing_fileds;
      }, 50, 2);

      Thank You

    • #39555
      d-n-13
      Participant

      Hi,

      Thanks for your most awesome support, the code is causing console error, and wp-admin > appearance > menus don’t show up anymore. https://www.dropbox.com/s/b6pnpj9tpzoigop/cod%20code%20menu%20error.JPG?dl=0

    • #39597
      WCFM Forum
      Keymaster

      Hi,

      Are you sure this code causing this?

      This code works only for site frontend then how this can break Appearance menu?

      If you disable this code that page works perfectly!
      Did you checked?

      Thank you

    • #39639
      d-n-13
      Participant

      Hi,

      I don’t know why it is causing the error, but I manually removed the code and the error is gone, I put it back the error is shown again.

    • #39642
      WCFM Forum
      Keymaster

      Hi,

      I have just tweak that code a bit, use this one and take a look ->

      // Payment Gateway Control
      add_filter( 'woocommerce_available_payment_gateways', function( $available_gateways ) {
      	global $WCFM;
      	if( !is_admin() && isset( $available_gateways['cod'] ) ) {
      		$cod_available = false;
      		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
      			$cod_available = false;
      			$_product     = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
      
      			if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
      				$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $_product->get_id() );
      				if( !$vendor_id || !wcfm_is_vendor( $vendor_id ) ) continue;
      				$vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
      				if( !$vendor_data ) $vendor_data = array();
      				$is_cod_enabled = isset( $vendor_data['payment']['wcfm_cod_enabled'] ) ? 'yes' : 'no' ;
      				if( $is_cod_enabled == 'yes' ) {
      					$cod_available = true;
      				}
      			}
      		}
      		
      		// Unset COD
      		if( !$cod_available )
      			unset( $available_gateways['cod'] );
      	}
      	
      	return $available_gateways;
      }, 200 );
      
      // Vendor Setting
      add_filter( 'wcfm_marketplace_settings_fields_billing', function( $vendor_billing_fileds, $vendor_id ) {
      	$vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
      	if( !$vendor_data ) $vendor_data = array();
      	$is_cod_enabled = isset( $vendor_data['payment']['wcfm_cod_enabled'] ) ? 'yes' : 'no' ;
      	
      	$vendor_wcfm_cod_enabled_fileds = array(
      													'wcfm_cod_enabled' => array('label' => __('COD Enable for Checkout', 'wc-frontend-manager'), 'name' => 'payment[wcfm_cod_enabled]', 'type' => 'checkbox', 'class' => 'wcfm-checkbox wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele checkbox_title', 'value' => 'yes', 'dfvalue' => $is_cod_enabled ),
      													);
      	$vendor_billing_fileds = array_merge( $vendor_wcfm_cod_enabled_fileds, $vendor_billing_fileds );
      	return $vendor_billing_fileds;
      }, 50, 2);

      Thank You

    • #39648
      d-n-13
      Participant

      Now it’s working !

      Thanks

    • #39649
      WCFM Forum
      Keymaster

      Great 🙂

Viewing 22 reply threads
  • The topic ‘Activate/Deactivate COD by vendors when desired.’ is closed to new replies.