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 );
Related
I'm trying to disable a number of WC Subscriptions emails (so they don't get sent). I know that I can do this in the admin settings area manually however I'm trying to do this via PHP (in a plugin). The reason for this is so that when it's moved from the test site to the live site the relevant files can be simply copied across and it's good to go without any manual settings changes.
As an example - removing the new renewal order that gets sent to the site admin.
add_action( 'woocommerce_email', 'SA_unhook_unneeded_emails' );
function SA_unhook_unneeded_emails( $email_class ) {
//remove new_renewal_order email (sent to admin)
remove_action( 'woocommerce_order_status_pending_to_processing_renewal_notification', array( $this, 'trigger' ) );
remove_action( 'woocommerce_order_status_pending_to_completed_renewal_notification', array( $this, 'trigger' ) );
remove_action( 'woocommerce_order_status_pending_to_on-hold_renewal_notification', array( $this, 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_processing_renewal_notification', array( $this, 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_completed_renewal_notification', array( $this, 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_on-hold_renewal_notification', array( $this, 'trigger' ) );
//remove_action( 'woocommerce_order_status_completed_renewal_notification', array( $this, 'trigger' ) );
}
Uncommenting the last remove_action makes no difference. The emails are still sent. I've tried changing woocommerce_email to wp_head to see if made any difference but none whatsoever.
There seems to be little documentation (at least that I can find) on the WC subscriptions hooks so I'm struggling to work out what exactly I need to do to get this working.
Any help would be appreciated.
Never mind found it - all I needed was a good nights sleep! For those who stumble across this later on the details are below.
You need to use the 'woocommerce_email_enabled_'.this->id filters. The id (this->id) can be found in the relevant class files for that email type. e.g.
New order (sent to admin) is in class-wc-email-new-order.php (woocommerce/includes folder) contains $this->id = 'new_order';
New renewal order (sent to admin) is new_renewal_order
Renewal order (send to customer) is either customer_processing_renewal_order or customer_completed_renewal_order
//stop emails without using the admin dashboard to manually set enabled/disabled status
add_filter( 'woocommerce_email_enabled_new_order', 'SA_stopemails', 10, 2); //new order sent to admin
add_filter( 'woocommerce_email_enabled_customer_on_hold_order', 'SA_stopemails', 10, 2); //order on hold sent to customer
add_filter( 'woocommerce_email_enabled_customer_processing_order', 'SA_stopemails', 10, 2); //order in processing sent to customer
add_filter( 'woocommerce_email_enabled_new_renewal_order', 'SA_stopemails', 10, 2); //new renewal order sent to admin
add_filter( 'woocommerce_email_enabled_customer_processing_renewal_order', 'SA_stopemails', 10, 2); //renewal order processing sent to customer
add_filter( 'woocommerce_email_enabled_customer_completed_renewal_order', 'SA_stopemails', 10, 2); //renewal order completed sent to customer
function SA_stopemails( $active, $order ) {
return false;
}
I try add custom notify using this tutorial https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/.
I hooked on 'woocommerce_order_status_changed', but my trigger method not work.
add_action( 'woocommerce_order_status_changed', array( $this, 'trigger' ) );
I try use this https://wordpress.stackexchange.com/questions/50738/why-do-some-hooks-not-work-inside-class-context, but it not work for my.
I have a custom field on user profiles on the admin side.
I would like to be able to check the value of this custom field an display a message in some cases.
I looked at the wordpress documentation, read about the profile_update hook, but it fires after the update.
And besides I wonder how I could display a message.
Thanks for your help.
Ok so I used the following hooks to add the fields
add_action( 'show_user_profile', 'add_custom_user_profile_fields' );
add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
and to check before update
add_action( 'personal_options_update', 'save_custom_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_custom_user_profile_fields' );
checkout this codex link it useful for you
https://codex.wordpress.org/Plugin_API/Action_Reference/personal_options_update
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
Im trying to change the hook associated with a plugin method.
The plugin is calling the method with this:
add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'vat_number_field' ) );
My goal is to remove that action and assign it to another hook, i've tried with the following with no success:
remove_action( 'woocommerce_before_checkout_form', array( $WC_EU_VAT_Number, 'vat_number_field'), 10 );
Thanks for any help.
To remove an action created from a class you should call that class to remove it
global $the_class;
remove_filter( 'woocommerce_checkout_before_customer_details', array($the_class, 'vat_number_field') );
and the priority must be the same (10 by default) set to create the action.
then you can add a new method to that hook.