I import orders from Shopify into Wordpress using a plugin, it works fine the orders are created. I'm using the Shopify API to import data from the order Timeline, since the sync plugin isn't capable of doing that on its own. But I need the Shopify ID to import the correct Timeline data, which is stored by the sync plugin as order meta data.
I'm using the action save_post_shop_order which fires every time a new order is imported from Shopify. The problem is, it fires before the meta data is saved, which means the Shopify_ID meta data is always empty, failing to import the Timeline data. If I save the order again, it works fine and imports the Timeline data correctly. save_post_shop_order fires again when an order is saved, and the Shopify_ID meta is available at that point, so it works when saving an already existing order, but not when the Order is first added.
I want a Woocommerce action that fires -after- the Order meta is stored. Some actions to consider:
woocommerce_thankyou : won't work since there is no checkout involved
save_post_shop_order : doesn't work because it's fired before meta is saved in an order
woocommerce_checkout_update_order_meta : there is no checkout, order is created with code
woocommerce_saved_order_items : triggers before meta is saved
From reading this post: WooCommerce: what hook AFTER order is saved/updated from ANY context
I tried using woocommerce_after_order_object_save but that caused a memory overflow, not sure why that happened. Plus it appears to be called on every object change.
Any suggestions?
Edit
The sequence of events:
An order is made in Shopify
Plugin gets the Order and transfers it to Woocommerce
Order is created in Woocommerce by the plugin
save_post_shop_order action hook is triggered, but the meta data required (Shopify_ID) is not yet saved, only the rest of the Order data
I try to get Timeline data for that Order but fails because the Shopify ID isn't valid
After save_post_shop_order is finished, the order is saved WITH the Shopify_ID as well
I want to find an action that executes -after- step 6, because what I've tried is fired either at step 4, or at checkout (I have no checkout)
Related
I am using Woocommerce on a locally hosted WordPress.
I would like the 'Place order' button in the order review section/checkout section of Woocommerce to process the order using AJAX (so that the order details are added to the database without refreshing the page).
I can't seem to find any information on this anywhere. Thanks
You'll have to add an eventlistener to the "Place order" button's click event, and prevent the default behaviour. Then use Ajax to make a POST request to the WooCommemerce REST API's order endpoint. The documentation contains all the information needed to set it up, and examples of such requests.
You can use the response to update your page with relevant information.
I have some code that generates a WooCommerce order in the backend using wc_create_order(). My issue is that none of the order actions get called like they would if you had made an order through the front end. For example I have the Xero plugin integrated with WooCommerce but if I create the order using wc_create_order() the invoice never gets sent to my Xero account.
What I want to know is how could I trigger the following xero invoice order action (shown in image on woocommerce order) without having to go to the order page and manually send them.
I have possibly found the action I want to call manually it can be found in the setup_hooks() function on this page git hub link. Is it possible for me to call the woocommerce_order_action_xero_manual_invoice action manually if so how?
You will want to call do_action('woocommerce_order_action_xero_manual_invoice', $order).
$order must be an object of class WC_Order.
On woocommerce, I add a new variation to a product. I have a hook configured for product.updated to my API.
Once the hook is received on my API for the updated product, I do a get variations API call hoping to get a list including the newly added variation.
Sometimes, the response includes the newly added variations. Other times, it does not.
The same thing happens with updating variations. If I update the regular_price and publish the changes, product.updated hook fires to my API. When I do get variations again, that variation in the response still has the former price.
I realized that if I call get variations like 1 or 2 mins after product.updated hook was fired, I will receive all variations including updates in the response.
What could be going on in woocommerce?
Does woocommerce generate an id for a variation and trigers a hook before taking time to build the object? This might explain why it works after a while.
Any other ideas?
I'm using Automattic\WooCommerce\Client lib.
woocommerce REST v3
woocommere v3.9.2
I need to make a woocommerce based system that will take order and it will send the order information to a third party POS system by wsdl. If the POS reply me with success message then i will save the order information into woocommerce database . If the POS reply me with error then i will show custom message to woocommerce user without saving the order info into db .
So i need to know the woocommerce order form action location / file name in where i can write my own code before it saves to db .
Thanks
Md. Muntasir Rahman Rafi
Ok , i got solution for my questions . The woocommerce checkout form action is taking at its library class called class-wc-checkout.php
In this class there is method named create_order(). In this method the woocommerce is taking actions on checkout form submitted data .But woocommerce allow some necessary hook to perform our task .
"woocommerce_before_checkout_process".
This hook will be called before the order process .Below i am giving sample code .
function custom_checkout(){
//Your code here
print_r($_POST);
}
add_action( 'woocommerce_before_checkout_process', 'custom_checkout');
I am using latest wp and wc and I am trying to add a form field in the frontend single product page where the user will be able to add comments which when the order is done the data will be available under woocommerce -> orders. Have anybody done that or it's not even possible because woocommerce is pretty limited for stuff like this?