In which files woocommerce saves order data into database - php

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');

Related

Woocommerce action after an order is saved with code (not checkout)

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)

WooCommerce - How to Call an Xero Action

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.

How and where I should add some action after successful payment in WooCommerce?

I use WordPress and WooCommerce in my site to sell some rent service.
After user's successful payment, I need to generate access pass code for the user. For pass code generation I use php script, but I don't understand where I should place it. I've tried to place it in /plugins/woocommerce/templates/checkout/thankyou.php file, it works, but when user refresh this page, scripts starts again and user get new pass code - this is not good.
So, first question is: where and how I should start my PHP-code to generate pass code after successful payment?
Second question is: how I should store this pass code in user's personal cabinet? I have idea to store this pass code in order's meta data, but I can't find out how I should set this data and get this data from DB.
You can use the woocommerce_payment_complete hook to execute your function.
function execute_post_payment_functions( $order_id ){
// Write your code to generate password here
}
add_action( 'woocommerce_payment_complete', 'execute_post_payment_functions' );
You can add the above code in functions.php of active theme/child theme

Woocommerce local pick shipping method show new field in checkout under the chosen method

I wonder if someone can help me out with woocommerce local pick shipping method.
What I want to achive is to show the new field I added inside the shipping method at the checkout page.
For example I added the field My additional information where you can type the street adress etc.
The problem is , its not showing in the checkout page as you can see below.
The file is here ,code a little to long to paste it .
https://github.com/woocommerce/woocommerce/blob/master/includes/shipping/local-pickup/class-wc-shipping-local-pickup.php
Maybe some of you knows how to use this hook ?
https://docs.woocommerce.com/wc-apidocs/class-WC_Shipping_Local_Pickup.html
Thank you very much.

prestashop 1.6 custom field

I have integrated an iframe in a custom module for the checkout (carrier), lets say that I want to get the value of a hidden input onclick of a button (in the iframe) to store it somewhere (maybe cookie) to finnaly send it to a third party api (with details of the order that I already have) , how can I do that ? prestashop 1.6 -custom module
I have seen a lot of "such" kind of modules. Customer select post terminal. Enter custom values and etc on carrier step (custom carrier module).
90% they have added a custom JS code to TPL file (or create A JS file and hook to header). After customer select, enter a value just send (AJAX post) to your controller or simple php file where you can save it to database. Use id_cart to assign to this cart.
On action hook - order validation assign id_order to your database (id_cart, id_order, customer_custom_value). Thats it! Now you can use it in BO, mails and etc.

Categories