Exclude payment methode depending on product or category
4 weeks 7 hours ago #373173
by Rixters
Exclude payment methode depending on product or category was created by Rixters
-- HikaShop version -- : 6.5.2
-- Joomla version -- : 6.1.3
-- PHP version -- : 8.3.x
Hi,
Is is possible to exclude a payment option if a certain product (or a product from a certain category) is selected in the cart? I want to hide a payment option when a large product is selected so payment only can be done via bank transfer.
Hope you have a trick.
Thanks
-- Joomla version -- : 6.1.3
-- PHP version -- : 8.3.x
Hi,
Is is possible to exclude a payment option if a certain product (or a product from a certain category) is selected in the cart? I want to hide a payment option when a large product is selected so payment only can be done via bank transfer.
Hope you have a trick.
Thanks
Please Log in or Create an account to join the conversation.
4 weeks 3 hours ago #373174
by nicolas
Replied by nicolas on topic Exclude payment methode depending on product or category
Hi,
There is no restriction on the product or the category for payment methods. What you have in the Restrictions section of the payment method is: zone, postcode, shipping method, currency, min/max price, min/max quantity, min/max weight and min/max volume.
Since you describe it as a large product, the min/max weight or the min/max volume restriction is probably all you need, and it requires no code. Set the weight or the dimensions on the large products, then set a max weight or a max volume on the payment methods you want to hide. HikaShop adds up the cart and hides the method as soon as the total goes over.
If you really need it per product or per category, it takes a small plugin listening on the onPaymentDisplay event of HikaShop. Something like this, as a system plugin, hides the payment methods 2 and 3 as soon as a product of the category 15 is in the cart:
The payment ids are the ones in the URL when you edit the payment method in the backend. Both loops are there on purpose: depending on the order the plugins run in, the methods are either still in $methods or already in $usable_methods.
For a rule on the products instead of the categories, drop the query and test the product ids directly in $ids.
There is no restriction on the product or the category for payment methods. What you have in the Restrictions section of the payment method is: zone, postcode, shipping method, currency, min/max price, min/max quantity, min/max weight and min/max volume.
Since you describe it as a large product, the min/max weight or the min/max volume restriction is probably all you need, and it requires no code. Set the weight or the dimensions on the large products, then set a max weight or a max volume on the payment methods you want to hide. HikaShop adds up the cart and hides the method as soon as the total goes over.
If you really need it per product or per category, it takes a small plugin listening on the onPaymentDisplay event of HikaShop. Something like this, as a system plugin, hides the payment methods 2 and 3 as soon as a product of the category 15 is in the cart:
Code:
<?php
defined('_JEXEC') or die();
class plgSystemHikapaymentrestriction extends \Joomla\CMS\Plugin\CMSPlugin {
// the payment methods to hide, and the categories which hide them
protected $payment_ids = array(2, 3);
protected $category_ids = array(15);
public function onPaymentDisplay(&$order, &$methods, &$usable_methods) {
if(empty($order->products) || empty($methods))
return true;
$ids = array();
foreach($order->products as $product) {
$ids[] = (int)$product->product_id;
if(!empty($product->product_parent_id))
$ids[] = (int)$product->product_parent_id;
}
$db = \Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$db->setQuery('SELECT COUNT(*) FROM '.hikashop_table('product_category').
' WHERE product_id IN ('.implode(',', $ids).')'.
' AND category_id IN ('.implode(',', $this->category_ids).')');
if(!$db->loadResult())
return true;
foreach($methods as $k => $method) {
if(in_array((int)$method->payment_id, $this->payment_ids))
unset($methods[$k]);
}
foreach($usable_methods as $k => $method) {
if(in_array((int)$method->payment_id, $this->payment_ids))
unset($usable_methods[$k]);
}
return true;
}
}
The payment ids are the ones in the URL when you edit the payment method in the backend. Both loops are there on purpose: depending on the order the plugins run in, the methods are either still in $methods or already in $usable_methods.
For a rule on the products instead of the categories, drop the query and test the product ids directly in $ids.
Please Log in or Create an account to join the conversation.
4 weeks 2 hours ago #373180
by Rixters
Replied by Rixters on topic Exclude payment methode depending on product or category
Thanks for the help! I'll see if I can create a plugin for that.
The following user(s) said Thank You: nicolas
Please Log in or Create an account to join the conversation.
Time to create page: 0.196 seconds