'woocommerce_payment_complete' is the hook that is triggered when payment is flagged as accepted by your payment gateway in WooCommerce.
It's a really useful hook because you can make things happen as soon as payment passes.
The problem I'm having it testing custom functions I attach to the hook - it is extremely laborious.
Basically, every time I want to test one of my functions attached to this hook I have to fill up my card, go through check out, submit payment then analyse what happens. If there's a bug or error then I have to fill up my card, go through check out, submit payment then analyse what happens all over again.
I'm losing hours doing this, so I was wondering, does anyone have a dev tip to make this less time consuming?
This hook is fired after the steps which (may) include financial transactions. Testing its contents does not actually require a financial transaction, but your wordpress does have to step through shopping cart events, in order to get you to the later point where the hook is fired.
What I did was to create a 100% discount coupon, so that I do not need to bother with
financial transactions when I modify/test code involved in this hook. That way I can quickly buy something from my shopping cart and then watch my logs output messages telling me about the code that is called when this hook is called, after the shop code has done its thing.
Related
I need to emit / send a custom event to Google Tag Manager when an order is eventually placed, so this order can be tracked.
The custom event should NOT be sent each time, when the WoocCommerce Thank you page is loaded, because the order would be tracked multiple times, when the page is reloaded.
So it should only be sent once for every order, when the final submit button is clicked AND the checkout form is valid.
I looked for wooCommerce DOM events, but couldn't found a suitable one...
I know there are plugins for that, but a plugin would be overkill for that I guess. We are a web agency and try to use as few plugins as possible and only necessary ones.
Unfortunately I have no clue, how I would emit an event on order placed... Any ideas or hints or even the solution to this? ;)
Thanks in advance, have a nice day
There are many solutions to this problem. As you mentioned, a plugin would be likely most suitable in the universe of Wordpress.
The next best solution is to open the documentation of woocommerce and see if you can find a callback for a successful order there. You emit an event from that callback if woocommerce doesn't do it already, which I believe you've checked.
Another solution would be sending the conversion on thank you loads, but have a logic in place that would not send more than one event with the same order id. And only when order id is defined. That would require you to surface the order id or find where it's surfaced.
A simpler yet dirty solution fitting woocommerce would be to just fire the conversion on the thank you page, but generate a cookie that would block the tag from firing again and let the cookie expire in N minutes, depending on whether you want to track repeated conversions from the same client.
It happens that the shopping behavior funnel is showing a strange behavior in Initiate checkout, the number of events launched is higher compared to those added to the cart and that could not be possible. I would like you to help me with this please.
enter image description here
I think you should check your e-comm settings: when event "check out" fires.
The issue strictly correlates with the way of how and where you're triggering the checkout started event. It looks like the event is triggered multiple times.
I had similar issues and in my case it was caused by incorrectly configured Google Tag Manager trigger which was firing at checkout and also on the order confirmation page.
I'm currently working on a multi STRIPE checkout for different STRIPE accounts based on the shipping country.
So far everything works smoothly by using the wc_stripe_params, wc_stripe_payment_request_params and woocommerce_stripe_request_headers filters and overloading the respective classes for the webhooks. There is one problem though.
Upon checkout page load, where the payment methods are, STRIPE renders CDATA values for their JS files.
When the initial shipping country guess through geoip database was correct and the customer doesnt change the shipping country, everything works fine, since the correct public keys were inserted into the JS of STRIPE. When the customer changes the shipping country there is no way to manipulate the already processed JS variables. This is why I want to split up the checkout process so that the last page is just for payment options based upon the before selected shipping country.
I know that there are multiple plugins for multi-step checkout available, but all use ajax for a smooth rendering, which results in the same error. I understand the way how to customize different processes in WP or WC, but I don't know how to really tackle this one since the formon the checkout page is posted to the wc_get_checkout_url() which needs payments selected and done - it doesnt look like there is a real multi step without ajax planned?
Thanks in advance for any help or thoughts
Problem solved by splitting up the checkout process into multiple forms and posting the data as one to the woocommerce checkout controller
Apologies for not knowing the exact terms to describe what I want, but I am using a simple WordPress theme site, the included WPForms plugin, and am trying to take orders using Square as my payment processing.
The current system I'm using works: I have a WPForm that gets the order information I need, they submit the form, then that redirects to a page where they click a link and arrive at the payment window on Square.
The problem is that I'm finding there's abandonment between the order form sending and the payment -- so I get orders in my Inbox, then have to wait and eventually track down whether they're wanting to pay. I'd really love to have my order arrive ONLY if payment is completed.
I could do this most simply by reversing the process, requiring someone pay first, THEN redirect to the order page...but that's a bad customer experience and I think people are more invested in completing a purchase if they're already excited by "ordering" it.
So I'm hoping someone can tell me if there's a plugin or method such that the very same "Order now" button will send the order to me AND process (and complete) the payment.
If this is more complicated than I think, if it's a huge headache, I will opt for either leaving it as is and tracking down payment...or reverse and make them pay first. But any help or suggestions, particularly for a Plugin that can do what I'm looking for, would be great. Thank you in advance!
If you're willing to purchase the Pro version of WPForms then it easily integrates with Stripe to collect payment at the same time that your Form is submitted.
https://wpforms.com/how-to-accept-payments-with-stripe/
PayPal and Authorize.Net are other options that integrate with WPForms.
These other questions may be relevant as well:
Wordpress action hook not firing (wpforms)
Wordpress Help (WPForms + PayPal Workflow)
I've been looking for an answer to this. Client has a woocommerce shop that will only ever have one of each product. What I need to accomplish is that when a product is added to their cart, the item is unavailable for anyone else to add the same product to a cart. I've tried the old plugin but it breaks portions of the front end, I've tried using several similar solutions I've found here, but nothing seems to do the trick. The plugin also made inventory management on the backend a total nightmare.
So, to walk you through, user A adds product A to cart. User B tries to add this product to cart but woocommerce says its sold out currently to user B. User A can checkout with product A or if user A closes the browser, woocommerce waits one minute and then puts product A back in stock so person B can then add product A to their cart.
I've been searching for this and have come up with nothing from here and some company claiming they can but it's done case by case and they want to handcode it aka very expensive to do.
Please, help!
Just an opinion here so maybe I am wrong, but woo commerce uses stock counts in the backend, so if this is set to 1, then there can only ever be one that can go through the checkout process unless cancelled.
The functionality to reduce that stock count to 0 whilst a user has that item in their basket (or just viewing the checkout page) is not feasible as they have not purchased, at that stage it is just showing intent to purchase.
As you mentioned, that functionality is possible, it wouldn't be pretty, but possible and not something that is available by default in the plugin. Development of such functionality would be needed, and you're right probably quite expensive for development time.