alexm Posted July 5, 2022 Share Posted July 5, 2022 Hi @kongondo I'd like to run a conditional based on which payment option was used in order-complete.php. What's the best way of retrieving the payment ID or class? Cheers mate. Link to comment Share on other sites More sharing options...
kongondo Posted July 5, 2022 Share Posted July 5, 2022 Hi @alexm, 3 hours ago, alexm said: order-complete.php This template file will receive $order as well as $orderLineItems, $orderCustomer and a bunch of other variables shown below: <?php namespace ProcessWire; /** @var WireData $order */ /** @var WireArray $orderLineItems */ /** @var float $orderSubtotal */ /** @var bool $isOrderGrandTotalComplete */ /** @var bool $isOrderConfirmed */ Payment info is in $order. We save the title of the payment method. You can use that by itself or use it to grab the payment gateway/method page itself (e.g. if you want the ID for some reason. Here's an example: <?php namespace ProcessWire; // COMPLETED ORDER /** @var WireData $order */ bd($order, __METHOD__ . ': $order at line #' . __LINE__); // PAYMENT GATEWAY/METHOD TITLE /** @var string $order->paymentMethod */ bd($order->paymentMethod, __METHOD__ . ': $order->paymentMethod at line #' . __LINE__); # OR ALIAS /** @var string $order->payment */ bd($order->payment, __METHOD__ . ': $order->payment at line #' . __LINE__); /** @var string $paymentGatewayTitle */ $paymentGatewayTitle = $order->payment; /// GET ID OF PAYMENT GATEWAY/METHOD /** @var int $paymentGatewayPageID */ $paymentGatewayPageID = (int)$padloper->getRaw("template=payment-provider,title={$paymentGatewayTitle}", 'id'); bd($paymentGatewayTitle, __METHOD__ . ': $paymentGatewayTitle at line #' . __LINE__); bd($paymentGatewayPageID, __METHOD__ . ': $paymentGatewayPageID at line #' . __LINE__); // IN CASE YOU WANT THE PAGE ITSELF FOR SOME REASON /** @var Page $paymentGatewayPage */ $paymentGatewayPage = $padloper->get("template=payment-provider,title={$paymentGatewayTitle}"); bd($paymentGatewayPage, __METHOD__ . ': $paymentGatewayPage at line #' . __LINE__); Hope this helps. 1 Link to comment Share on other sites More sharing options...
alexm Posted July 6, 2022 Author Share Posted July 6, 2022 I think it does... haha. So I can check with for instance: if ($order->paymentMethod == Invoice) Or no? 1 Link to comment Share on other sites More sharing options...
kongondo Posted July 6, 2022 Share Posted July 6, 2022 1 hour ago, alexm said: So I can check with for instance: if ($order->paymentMethod == Invoice) Or no? Defo! <?php if ($order->paymentMethod == Invoice){ echo 'Mate, clock is ticking! :-)'; } Sorry I wasn't clear. 1 Link to comment Share on other sites More sharing options...
alexm Posted July 6, 2022 Author Share Posted July 6, 2022 Hahaha! Clock is ticking. Creased when I saw that!! Cheers as always! Link to comment Share on other sites More sharing options...
alexm Posted October 3, 2022 Author Share Posted October 3, 2022 On 7/6/2022 at 11:10 PM, kongondo said: On 7/6/2022 at 9:47 PM, alexm said: So I can check with for instance: if ($order->paymentMethod == Invoice) Or no? Defo! So, it's just been brought to my attention that this isn't working. Should it in fact be if ($order->payment == Invoice) to get the actual title? Link to comment Share on other sites More sharing options...
kongondo Posted October 3, 2022 Share Posted October 3, 2022 Hi @alexm, 1 hour ago, alexm said: So, it's just been brought to my attention that this isn't working. Should it in fact be Strange. It works here. Both $order->payment and $order->paymentMethod should work (see TracyDebugger grab below). Screenshot Just confirming that you have a custom order-complete.php at /site/templates/padloper/order-complete.php ? 1 Link to comment Share on other sites More sharing options...
alexm Posted October 7, 2022 Author Share Posted October 7, 2022 Hmm, I added logs between the if statement and they aren't being written so I assume that it's failing before this. Could if be that I'm trying to get the product ID incorrectly? Sorry about this mate. // forach product in the order foreach ($orderLineItems as $p) { // check to see if it is a membership product and if the user is logged in if (in_array($p->product_id, [8473, 8474]) && $user->isLoggedin()) { // if the order is not of payment type PaymentInvoice (bank transfer) wire()->log->save('wes-checkout', 'There is a membership product in the order.'); if ($order->payment != 'Invoice') { wire()->log->save('wes-checkout', 'Member should automatically be made active.'); Link to comment Share on other sites More sharing options...
kongondo Posted October 7, 2022 Share Posted October 7, 2022 2 hours ago, alexm said: Could if be that I'm trying to get the product ID incorrectly? Yep. That's exactly it. My bad, docs are still lagging. 2 hours ago, alexm said: $p->product_id This should be one of the following: <?php namespace ProcessWire; $p->productID; // aliases $p->lineItemProductID; $p->orderItemProductID; Let me know if it works. 1 Link to comment Share on other sites More sharing options...
alexm Posted October 7, 2022 Author Share Posted October 7, 2022 8 minutes ago, kongondo said: Yep. That's exactly it. My bad, docs are still lagging. 2 hours ago, alexm said: Nah, not at all. I could have done better digging. I thank you sir! I'll report back. Thank you as always!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now