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.
Related
The Woocommerce Subscriptions plugin is using a function called with action:
add_action( 'template_redirect', array( &$this, 'maybe_setup_cart' ), 100 );
I need to remove this action in my plugin, as it is causing unwanted effects.
I have tried creating an action before it in plugin construct, to override it:
add_action('template_redirect', array( &$this, 'maybe_setup_cart' ), 98);
In it i am also trying to remove the action:
remove_action( 'template_redirect', 'maybe_setup_cart', 100 );
This is also not working.
How can i disable the action from another plugin?
You can copy function shared here:
https://github.com/herewithme/wp-filters-extras/blob/master/wp-filters-extras.php
Next simply do
remove_filters_with_method_name( 'template_redirect', 'maybe_setup_cart', 100 );
I tried and It works :)
Thanks
I want to replace the Subscription Totals given by the WooCommerce Subscriptions with my plugins version of Subscription Totals table.
In the WooCommerce Subsciptions plugin's class-wcs-template-loader.php there is a line that loads the subscription total template
add_action( 'woocommerce_subscription_totals_table', array( __CLASS__, 'get_subscription_totals_template' ) );
I'm trying to remove the function from the hook and replace it my own version of template. But it is not working!
I've written the following in my plugin file
remove_action( 'woocommerce_subscription_totals_table', array( __CLASS__, 'get_subscription_totals_template' ) );
but it is not working.
Put this instead:
remove_action( 'woocommerce_subscription_totals_table', array( 'WCS_Template_Loader', 'get_subscription_totals_template' ) );
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'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 );
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.