Enable PayPal but Only when Product ID 1234 is in cart?
We don't use PayPal generally. However, we would like PayPal to be an option when customers have a specific product ID in their cart. Is there a way to customise the code for this?
Maybe a tweak I could make to \includes\modules\payment\paypalwpp.php ?
Re: Enable PayPal but Only when Product ID 1234 is in cart?
Quote:
Originally Posted by
limelites
We don't use PayPal generally. However, we would like PayPal to be an option when customers have a specific product ID in their cart. Is there a way to customise the code for this?
There's always a way to customise code :)
Quote:
Originally Posted by
limelites
Maybe a tweak I could make to \includes\modules\payment\paypalwpp.php ?
I can't see why that wouldn't work.
Do a search for threads discussing how to enable/disable specific shipping methods based on particular products. (There are serveral of them).
The same principles would apply for the payment methods... Essentially it involves just setting the "$this->enabled" to be true or false on demand.
Cheers
Rod
Re: Enable PayPal but Only when Product ID 1234 is in cart?
Quote:
Originally Posted by
RodG
There's always a way to customise code :)
I can't see why that wouldn't work.
Do a search for threads discussing how to enable/disable specific shipping methods based on particular products. (There are serveral of them).
The same principles would apply for the payment methods... Essentially it involves just setting the "$this->enabled" to be true or false on demand.
Cheers
Rod
Hi Rod,
I've searched prior to posting and there's one thread in particular that's useful but it's a closed thread so I can't post a reply there and it's sort of doing the opposite of what I need:
http://www.zen-cart.com/showthread.p...rtain-products
In the thread above, they're de-activating PayPal on certain products. My problem is that as soon as I activate the PayPal module, it will be active for all 1100 products on the site. I want to activate the PayPal module but immediately have it disabled for all products, unless the product ID is 1234.
So I'm struggling to find a way. Any help would be greatly appreciated.
Re: Enable PayPal but Only when Product ID 1234 is in cart?
Quote:
Originally Posted by
limelites
it's sort of doing the opposite of what I need:
they're de-activating PayPal on certain products.
My problem is that as soon as I activate the PayPal module, it will be active for all 1100 products on the site. I want to activate the PayPal module but immediately have it disabled for all products, unless the product ID is 1234.
So I'm struggling to find a way. Any help would be greatly appreciated.
It is *exactly* the same principle, but the logic needs to be reversed.
Near the start of the code wil lbe something like
$this->enabled = ((MODULE_PAYMENT_PAYPAL_STATUS == 'True') ? true : false);
What this is doing is reading the admin configuration setting for the module to set the 'default'. IOW, if MODULE_PAYMENT_PAYPAL_STATUS == 'True' then $this->enabled will be set to 'true'. Otherwise it will be set to false.
Changing $this->enabled at some point *after* the code above will act as an over-ride for this setting. So, a single line like
$this->enabled = false ;
Will have the same effect as if you had disabled the module from your admin settings.
Now all you need to as add your product check, and if found, set $this->enabled = true ;
Something like:
// enable if products_id 1234 is in the cart
if ($_SESSION['cart']->in_cart_check('products_id','1234') > 0) { $this->enabled = true;}
Cheers
Rod
Re: Enable PayPal but Only when Product ID 1234 is in cart?
Hi Rod,
I don't have time to try this at the moment as we're just about to leave for the weekend but thank you for the very clear and concise tutorial with a breakdown of the logic and syntax required. You've been really helpful. Thank you!
Re: Enable PayPal but Only when Product ID 1234 is in cart?
Update.... Ten minute delay so I gave it a whil but it doesn't seem to work. I enabled PayPal Express in admin, then edited /includes/modules/payment/paypalwpp.php with this:
function paypalwpp() {
include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
global $order;
$this->code = 'paypalwpp';
$this->codeTitle = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
$this->codeVersion = '1.3.8a';
$this->enableDirectPayment = (MODULE_PAYMENT_PAYPALWPP_DIRECT_ENABLED == 'True');
$this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
// disable, (even when admin has it switched on):
$this->enabled = false;
// enable if products_id XXXX is in the cart:
if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0) { $this->enabled = true;}
It doesn't seem to do anything, PayPal express is enabled no matte what's in the cart. I think something's missing or not quite right.
Re: Enable PayPal but Only when Product ID 1234 is in cart?
Try changing the code for line:
Code:
// disable, (even when admin has it switched on):
$this->enabled = false;
if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0) { $this->enabled = true;}
to read:
Code:
if (!IS_ADMIN_FLAG) {
// disable, (even when admin has it switched on):
$this->enabled = false;
if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0) {
$this->enabled = true;
}
}
Re: Enable PayPal but Only when Product ID 1234 is in cart?
Quote:
Originally Posted by
limelites
Update.... Ten minute delay so I gave it a whil but it doesn't seem to work..
Please follow any and all suggestions provided by http://www.zen-cart.com/image.php?u=...ine=1325513042 Ajeh
The info I gave was 'off the top of my head' with a couple of 'crude' cut and pastes to demonstrate what would be required.
Ajeh on the other hand is the real expert in this type of modification and her advice and suggestions usually produce something fully functional :)
I bow to her expertise every time, without question :)
Cheers
Rod
ps. Thanks for stepping in Ajeh.
Re: Enable PayPal but Only when Product ID 1234 is in cart?
Always easy to clean up other's code ... especially when pretty close ... :cool:
Re: Enable PayPal but Only when Product ID 1234 is in cart?
I've tried and it doesn't work. PayPal option comes up regfardless of the product ID. Here's the link of code:
PHP Code:
function paypalwpp() {
include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
global $order;
$this->code = 'paypalwpp';
$this->codeTitle = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
$this->codeVersion = '1.3.8a';
$this->enableDirectPayment = (MODULE_PAYMENT_PAYPALWPP_DIRECT_ENABLED == 'True');
$this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
// disable, even when admin has it switched on:
if (!IS_ADMIN_FLAG) {
// disable, (even when admin has it switched on):
$this->enabled = false;
global $cart;
if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0) {
$this->enabled = true;
}
}
Maybe I'm editing the wrong file?