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.
Related
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)
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.
For example, to run my own function when woocommerce action is fired,
Do I need to authenticate first ?
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 want to run some of my own custom PHP code on the order details when the order confirmation page shows to the user in a Prestashop 1.5.5.0 - after he has returned from payment. It has to work on all types of payment, also pay-in-store options. On every order confirmation page.
Can anybody show me a simple script/method for that? Or maybe a good link?
You can use prestashop hook displayOrderConfirmation, which should be common to all payment methods. Just create a new function in your module
public function hookDisplayOrderConfirmation($params) {
//do whatever
}
and in module installation register this hook using $this->registerHook('displayOrderConfirmation');, which $params are passed to this function can be found at /controllers/front/OrderConfirmationController#displayOrderConfirmation().