I am trying to send a email when a order is moved to a custom status in woocommerce. I have successfully created a plugin that creates a custom status and order is assigned to the custom status.
I have also successfully added a custom email template under Settings -> Emails in WooCommerce and written code which should send a email when the order is moved to that custom status.
However that code is not getting triggered and email is not getting sent.
Below is my code.
apply_filters( 'woocommerce_email_actions', array('woocommerce_order_status_processing_to_partial-shipment'));
// Trigger on new paid orders
add_action( 'woocommerce_order_status_processing_to_partial-shipment_notification', array( $this, 'trigger' ) );
the action never comes in the trigger function i have written. I am using wordpress 4.5.3 and woocommerce version 2.6.4.
Can anyone suggest as to what could be going wrong. Thanks.
Since WooCommerce 2.3, you can use 'woocommerce_email_actions' filter, so you can try this:
function new_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_processing_to_partial-shipment_notification';
return $actions;
}
add_filter( 'woocommerce_email_actions', 'new_woocommerce_email_actions' );
Luck
Related
I know it’s possible to send customer directly to the checkout page by appending “add-to-car=product_id” to the checkout endpoint like this:
yourwebsite.com/checkout/?add-to-cart=12345
I was wondering if it’s a way to do the same when a product has subscription options? I use Woocommerce Subscriptions plugin to manage subscriptions and it doesn't create a separate variant for subscription product.
Based on these answers:
Woocommerce add to cart button redirect to checkout
WooCommerce Subscriptions - Check if a product is a subscription product
You can create a PHP script to change the redirect url after adding a product to the cart (by checking the product class type).
Furthermore, using the woocommerce_add_to_cart_redirect hook you have two parameters: $url and $adding_to_cart (product object). Here you find the documentation.
Then:
// redirects to checkout if the product added to the cart is a subscription
add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_to_checkout_if_product_is_subscription' );
function redirect_to_checkout_if_product_is_subscription( $url, $product ) {
if ( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
}
return $url;
}
The code must be added to your active theme's functions.php file.
I'd like to pass the payment method to the order notes section of a Woocommerce Order (when viewing the order in the backend)
This field gets imported into our ShipStation software. Right now, I have no way of knowing what payment method a customer used when viewing an order from ShipStation. (we give a free gift when a certain payment method is used.)
At first, viewing the payment method in Wordpress Admin is available. You just have to enable it in Screen Options.
If you want to add the Shipment method into the order note, you need to just add this to your functions.php:
add_action( ‘woocommerce_new_order’, ‘add_engraving_notes’, 1, 1 );
function add_engraving_notes( $order_id ) {
$order = new WC_Order( $order_id );
$note = $order->getShippingMethod();;
$order->add_order_note( $note );
$order->save();
}
I have an e-commerce site running on WordPress, I have added functionality in which whenever a user checkout, the API of my courier is hit and a tracking code is saved in the database.
Now I want to create a custom order from the backend (Add new order in Woocommerce) and do the same thing, like calling the API and saving the tracking returned from the API call to the database, but don't know which hook to use.
you should use 'woocommerce_new_order' hook:
add_action( 'woocommerce_new_order', 'api_call', 1, 1 );
function api_call( $order_id ) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
// etc...
}
fires after new order created
I'm developing a plugin over woocommerce. I want when a order is completed some custom fields to be filled. After that I want to add those custom fields to the email sent to the client.
I have used
add_action( 'woocommerce_order_status_completed', 'myplugin_woocommerce_order_status_completed', 10, 1 );
to fill the custom fields and
add_action( 'woocommerce_email_order_meta', 'woo_add_tickets_numbers_to_email' );
to add those fields to email.
My problem seems tha woocommerce_email_order meta get fired before woocommerce_order_status_completed and the fields are empty.
How can I force to execute first woocomerce_order_status_completed and send email after that?
Best regards
There is one way available to call "woocomerce_order_status_completed" this action before email send.
You can try using this code to trigger this function first,
add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ), 10, 2 );
instead of,
add_action( 'woocommerce_order_status_completed', 'myplugin_woocommerce_order_status_completed', 10, 1 );
Can anyone direct me to where I can find the file where I can change the "State/County" and "Zip Code" titles in a woocommerce checkout page?
WooCommerce offers hooks for this:
please check Customizing checkout fields using actions and filters
as you'll see on that page you can hook a function (that you'll save in your childs functions.php for example ) to WooCommerce checkout page and change the data that is available.
so your code will look something like:
/ Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_postcode']['label'] = 'My new postcode title';
$fields['shipping']['shipping_state']['label'] = 'My new state title';
return $fields;
}
other examples and fields on the linked page.