Payment method per vendor

Hello!
I have a question, I recently had a vendor ask to be able to pick which payment method is used for their listing. In their case, they only wanted cash on delivery. Is there a way I can implement this into the form where the profile is created for the vendor to select whether they want cash on delivery or direct deposit via stripe for that specific vendor and any listings they make??
Thanks in advance!

I have been doing a little thinking on it, and I was hoping to possibly add a toggle button in the vendors profile that disabled payouts for that specific vendor while simultaneously activating the cash on delivery option for checkout on their listings. This toggle button would serve 3 main purposes : disabling payouts to that vendor, activating the cash on delivery method at checkout on their listings, and allowing them to create a listing without creating a stripe account.

I realize this will probably require some customizations. I was just hoping to be pointed in the right direction!

1 Like

Please try this PHP snippet. Please add a vendor select attribute where a vendor can choose which payment method is activated for the vendors’ listings. Please change the attribute field name and payment method name in this code snippet

add_filter(
	'woocommerce_available_payment_gateways',
	function($available_gateways){
		
		if(!is_checkout() || !isset(WC()->cart)){
			return $available_gateways;
		}
		
		// Get product.
		$product = hivepress()->helper->get_array_value(hivepress()->helper->get_first_array_value(WC()->cart->get_cart()), 'data');
		
		if(!$product || !$product->get_parent_id()){
			return $available_gateways;
		}
		
		// Get listing.
		$listing = \HivePress\Models\Listing::query()->get_by_id( $product->get_parent_id() );
		
		if(!$listing){
			return $available_gateways;;
		}
		
		// Get vendor.
		$vendor = $listing->get_vendor();
		
		if(!$vendor || !$vendor->display_your_vendor_attribute_field_name()){
			return $available_gateways;
		}
		
		// Get vendor attribute value.
		$vendor_payment_data = $vendor->display_your_vendor_attribute_field_name();

		if($vendor_payment_data === 'some value'){
			
			// If vendor attribute value equal to some value then disable some payment method on the checkout.
			unset($available_gateways['put_payment_method_name_here']);
		}
		
		return $available_gateways;
	},
	1000,
	2
);
1 Like
  1. For the attribute field name do I need the field name and the ID of the specific selection?? If so, how would I format that correctly in the snippet? This is an example I made and pulled from the URL hp_vendor_preferred_payment_meth&tag_ID=583

  2. How do I format the payment methods correctly in the snippet?? The payment IDs are stripe_cc and stripe_googlepay?

  3. Will this also unset the Stripe account setup?? If they are doing cash, there is no need for them to set up a stripe account. Thank you!

  1. It is necessary to use the field name of the attribute, which is possible to get when trying to edit an attribute, and there is a field with the title Field name, which contains the field name of the attribute. As an attribute value to make the correct condition, please use the name of the option which you have set when clicking Edit Options in the attribute settings

  2. Yes, it seems like stripe_cc and stripe_googleplay is the correct payment method name, but it needs additional testing and checking. If it is the correct name, then please change put_payment_method_name_here on the payment method name in the code snippet and use the same structure to build the code conditions

  3. Unfortunately, this code snippet only allows managing payment methods depending on the vendor’s attribute value. It requires advanced customization to disable the requirement for Stripe account setup

I tried the above and its producing a critical error on the site when I proceed to checkout.

add_filter(
	'woocommerce_available_payment_gateways',
	function($available_gateways){
		
		if(!is_checkout() || !isset(WC()->cart)){
			return $available_gateways;
		}
		
		// Get product.
		$product = hivepress()->helper->get_array_value(hivepress()->helper->get_first_array_value(WC()->cart->get_cart()), 'data');
		
		if(!$product || !$product->get_parent_id()){
			return $available_gateways;
		}
		
		// Get listing.
		$listing = \HivePress\Models\Listing::query()->get_by_id( $product->get_parent_id() );
		
		if(!$listing){
			return $available_gateways;;
		}
		
		// Get vendor.
		$vendor = $listing->get_vendor();
		
		if(!$vendor || !$vendor->hp_vendor_preferred_payment_meth()){
			return $available_gateways;
		}
		
		// Get vendor attribute value.
		$vendor_payment_data = $vendor->hp_vendor_preferred_payment_meth();

		if($vendor_payment_data === '584'){
			
			// If vendor attribute value equal to some value then disable some payment method on the checkout.
			unset($available_gateways['stripe_googlepay']);
		}
		
		return $available_gateways;
	},
	1000,
	2
);

Please try this PHP snippet instead. Please change some value in the code snippet on the attribute value as described in the comment above this text in the code snippet. Also, please make sure that your Select type attribute has a field name that is equal to vendor_preferred_payment_meth as you have set in the code snippet. If this field name is correct, then use the suggested code snippet below without changing the attribute name

add_filter(
	'woocommerce_available_payment_gateways',
	function($available_gateways){
		
		if(!is_checkout() || !isset(WC()->cart)){
			return $available_gateways;
		}
		
		// Get product.
		$product = hivepress()->helper->get_array_value(hivepress()->helper->get_first_array_value(WC()->cart->get_cart()), 'data');
		
		if(!$product || !$product->get_parent_id()){
			return $available_gateways;
		}
		
		// Get listing.
		$listing = \HivePress\Models\Listing::query()->get_by_id( $product->get_parent_id() );
		
		if(!$listing){
			return $available_gateways;
		}
		
		// Get vendor.
		$vendor = $listing->get_vendor();
		
		// If your attribute has field name which is equal to "vendor_preferred_payment_meth" then please try the solution below.
		if(!$vendor || !$vendor->display_vendor_preferred_payment_meth()){
			return $available_gateways;
		}
		
		// Get vendor attribute value.
		$vendor_payment_data = $vendor->display_vendor_preferred_payment_meth();
	
		// Please use the name of the option not the option ID if you use Select attribute.
		if($vendor_payment_data === 'some value'){
			
			// If vendor attribute value equal to some value then disable some payment method on the checkout.
			unset($available_gateways['stripe_googlepay']);
		}
		
		return $available_gateways;
	},
	1000,
	2
);
add_filter(
	'woocommerce_available_payment_gateways',
	function($available_gateways){
		
		if(!is_checkout() || !isset(WC()->cart)){
			return $available_gateways;
		}
		
		// Get product.
		$product = hivepress()->helper->get_array_value(hivepress()->helper->get_first_array_value(WC()->cart->get_cart()), 'data');
		
		if(!$product || !$product->get_parent_id()){
			return $available_gateways;
		}
		
		// Get listing.
		$listing = \HivePress\Models\Listing::query()->get_by_id( $product->get_parent_id() );
		
		if(!$listing){
			return $available_gateways;
		}
		
		// Get vendor.
		$vendor = $listing->get_vendor();
		
		// If your attribute has field name which is equal to "vendor_preferred_payment_meth" then please try the solution below.
		if(!$vendor || !$vendor->display_vendor_preferred_payment_meth()){
			return $available_gateways;
		}
		
		// Get vendor attribute value.
		$vendor_payment_data = $vendor->display_vendor_preferred_payment_meth();
	
		// Please use the name of the option not the option ID if you use Select attribute.
		if($vendor_payment_data === 'cash_on_arrival'){
			
			// If vendor attribute value equal to some value then disable some payment method on the checkout.
			unset($available_gateways['stripe_googlepay']);
		}
		
		return $available_gateways;
	},
	1000,
	2
);

I used this snippet, it isnt giving me a critical error anymore, but it is not unsetting the payment method.

Are yall offering customizations at the moment??

Sorry, we don’t yet but we plan to start offering customization services (for non-complex features/adjustments at this time because we have a new developer) in 1-2 weeks.

Okay, thank you. I guess the snippet is not going to work then and will require customizations??

This code snippet allows only to manage checkout payment methods depending on a vendor’s attribute value. But it requires advanced customization to extend this functionality with additional logic

Okay, I will wait for y’all to offer customizations again. Please let me know when you do! Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.