How we can get the transaction details when placing the order in woocommerce, to use that details for some custom database or send that details to other server ?
I have used the woocommerce hook woocommerce_new_order but it only print the order details. Is any other hook to get the complete traction details ?
If you have order id you can simply get the transaction id by doing this:
$order = new WC_Order( $order_id );
$transaction_id = $order->get_transaction_id();
...
Check out WooCommerce docs to get more useful info.
Related
I am attempting to update WooCommerce products through notifications sent by a third party application. I have read the documentation on doing this and it seems easy enough, but it looks like the only way to use the API to update a product is by Product ID. Unfortunately, these are/were created incrementally while uploading the rather large product catalog into WooCommerce.
While making the .csv's and uploading to WooCommerce, we set the SKU's to be the same ID that the products have in the third-party software (book ISBN's). So I am able to send that number (the number that corresponds with SKU in WC) with the HTTP request, but that does not allow me to perform the product update.
It seems to me, the best way to accomplish this integration would be to change the product ID's of all my products in WooCommerce to be the same as this unique number that is currently the SKU. It doesn't appear as though this is possible to do in the dashboard or user interface, so I imagine I'll have to do it on a database level.
Does anyone know what tables will need to be modified or if there is a way to do this in the dashboard? Maybe even a tweak to my HTTP request to the API that will allow me to update by SKU?
Modifiy the Product IDs in the database directly is not a good choices.
This action is required to do every time when creating new products.
The most simplest and safe appoach is creating a new API,
which purpose for searching the product ID by SKU.
Here is a part of sample code.
function get_product_by_sku( $sku ) {
global $wpdb;
$product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );
if ( $product_id ) return new WC_Product( $product_id );
return null;
}
I am currently using a code similar to what I need, from LoicTheAztec ( who should really be called "DaMan"). That code triggers Woo to send an email to a custom email address when order status is changed to "Processing". Without that code, a notification email only goes to the customer.
For my case I want to send a notification to both the customer, and the store owner. I was able to tweak previous code to do this - but the result was that both the customer and owner get the same email ( as in, they are both copied on exact same notice from Woo).
Here is what I am currently using in my functions.php:
// notify when order status set to processing
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'processing_order_replacement_email_recipient', 10, 2 );
function processing_order_replacement_email_recipient( $recipient, $order ) {
// Set HERE your replacement recipient email(s)… (If multiple, separate them by a coma)
$recipient .= ',example#owneremail.com';
return $recipient;
}
How could I trigger this so that the customer gets their copy, and the owner gets her copy separately? Also typically the stock emails generated by WOO have slightly different text versions between customer and store owner.
If what I am asking can't be done, I'll stick with what I have. Just wondering if there is a cleaner way to achieve it. Thanks in advance for any assistance!
I am trying to delete an order from database i was tried using bellow function but this is not working.can any body tell me how to delete an order from db using order id.
<?php wc_delete_order_item( absint( $order_id ) ); ?>
WooCommerce Orders is custom post type, therefore you can use wordpress functions for performing any operation like,
wp_delete_post($order_id);
So I have an e-commerce site using wordpress and woo-commerce, now using the smart-coupon woocommerce plugin extension is there a way for me to create a credit coupon/gift-card (that initially has no email restriction) and manually assign the email of the current user as the email restriction for it the first time the gift-card is being used.
I'm trying to create a vooucher system using the giftcard as vouchers to purchase products in my store.
Since you don't have any code to show what you were using, try this.
$coupon_code = 'some-code-I-created';
$user = wp_get_current_user();//Get the current user object
$coupon = new WC_Coupon( $coupon_code );//Get the coupon object
$emails = $coupon->get_email_restrictions();//Returns an empty array or array of emails
$emails[] = strtolower($user->billing_email);//Add user's billing email address to the array
$emails = array_filter($emails);//Remove empty values
array_unique($emails);//Remove any duplicate values
$coupon->set_email_restrictions($emails);//Set the coupon's array with the updated array
$coupon->save();//Save the coupon
In case I'm adding email addresses in bulk (like using array_merge() instead of adding one address at a time), it's always good to make sure the array is clean by removing any empty values or duplicate values before updating the coupon object with it.
Also, WooCommerce compares the billing address in all lowercase but not the restricted emails in the coupon, so be sure when adding it to your coupon that you add it as all lowercase so they validate correctly. Source. This bug may be fixed in the future, but until then...
I can't figure out with this problem: when woocommerce sends the order processing mail to custumer, customer's meta properties are valorized in the $order object, and the valorization is done by the execution of the action woocommerce_email_order_meta (at least, I suppose):
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );
All fine with that, but when I want to create a custom template for that email, no meta values will be displayed in the result, although the same invokation.
I've checked the parameter values passed to the "woocommerce_email_order_meta" invokation (that routes to the order_meta() function in plugins/woocommerce/includes/class-wc-emails.php) of my costum template, and those values are the same.
Neither debugging the order_meta() function in both cases gave me clues, the function's behavior is always the same, but the result in the mail is different. So... what can I do for insert order meta info in this mail?
Sorry if this question is a duplicate and for my bad english.
Thanks in advance if you can help me with this issue.
Billing address and other details, such as first name and last name are stored as order details (In "postmeta" table). Whereas, Products in the order, its quantity, price is stored as Order meta.
Therefore, "woocommerce_email_order_meta" action will display order meta details.
Please make sure, you have included the below line, in your custom email template to get Billing address and other details.
<?php wc_get_template( 'emails/email-addresses.php', array( 'order' => $order ) ); ?>
For more information regarding, Email template customization, you can refer our blog ,
http://wisdmlabs.com/blog/customize-woocommerce-order-emails/