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;
}
Related
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 have Woocommerce website with the plugin Print Invoices/Packing Lists installed.
I'm trying to remove an action and I've narrowed down the action to this (shortened) code;
class WC_PIP_Document_Invoice extends WC_PIP_Document {
public function __construct( array $args ) {
parent::__construct( $args );
// add a "View Invoice" link on order processing/complete emails sent to customer
add_action( 'woocommerce_email_order_meta', array( $this, 'order_paid_email_view_invoice_link' ), 40, 3 );
}
}
So I'm looking at removing this using; https://codex.wordpress.org/Function_Reference/remove_action
However as the action as added within a class, I can't quite work out what to pass into the function name. Would it be something like;
remove_action( 'woocommerce_email_order_meta', array( 'WC_PIP_Document_Invoice', 'order_paid_email_view_invoice_link' ), 40 );
Can anyone point me in the right direction?
Many thanks
Try following code that should work for you.
add_action( 'init', 'wpse_106269_remove_hooks', 11 );
function wpse_106269_remove_hooks(){
remove_action( 'woocommerce_email_order_meta', 'action_woocommerce_email_order_meta', 10, 4 );
}
I'm trying to disable the license notification for a plugin a bought a few months ago. Now my license for updates is not longer valid but I don't want to receive any updates anymore because I've changed a lot in the plugin. This is the message:
I've tried to remove it this way:
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );
function filter_plugin_updates( $value ) {
unset( $value->response['cred-frontend-editor/plugin.php'] );
return $value;
}
But when I refresh the page the notification is still there. How can I remove it?
This depends on the plugin. But the steps I would take.
Search to plugin codebase for variations of add_action( 'admin_notices', 'callback_notice function')
Then try to use remove_action to de-hook that notice.
Keep in mind remove_action has to run after the add_action, So if that add_action is done inside an add_action('admin_init', ...,10) (prio 10) you should run the remove action in an add_action('admin_init', ...,11)
Yes this part is confusing.
Good luck
Edit
Given the code you provided the remove should be:
add_action( 'init', function() {
remove_action( 'admin_notices', array( WP_Installer::instance(), 'setup_plugins_page_notices' ) );
remove_action( 'admin_notices', array( WP_Installer::instance(), 'setup_plugins_renew_warnings' ), 10 );
remove_action( 'admin_notices', array( WP_Installer::instance(), 'queue_plugins_renew_warnings' ), 20 );
}, 100);
The add_actions are run in the init function. the init function is hooked in the , well the init hook, at default priority (10)
So we run the removes after that in the init hook at prio 11.
Probably you don't need to remove the setup_plugins_page_notices hook.
I am using WooCommerce Product Vendors plugin for vendor management.
Currently, when a new order is received the notification is sent to customer and admin. Once admin change order status to Processing or Completed then the email is sent to Vendor.
But I need to send that notification email when an order is received.
Can this be achieved by creating a filter in functions.php or maybe by triggering product status change notification on order received?
Updated: Added "New booking" email notification Id…
There is many ways to achieve that. Here I have 2 of them:
1). The first one, based on email ID "new Order". It is tested and works:
add_action ('woocommerce_email_customer_details', 'new_order_email_to_vendor', 20, 4 );
function new_order_email_to_vendor( $order, $sent_to_admin, $plain_text, $email ){
if( in_array( $email->id, ['new_order', 'new_booking'] ) ){
$mailer['WC_Product_Vendors_Order_Email_To_Vendor']->trigger( $order );
}
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
2). This is untested as it's based on order status change conditions. You can set in the if statement the "from" order statuses or some "to" order statuses or both…
Here I use the "from" 'pending' order status only, as all orders are always set in pending status during the payment process in Woocommerce:
add_action( 'woocommerce_order_status_changed', 'new_order_email_to_vendor', 10, 4 );
function new_order_email_to_vendor( $order_id, $old_status, $new_status, $order ){
if ( in_array( $new_status, array( 'processing','completed') ) { // <== Updated
$emails = WC()->mailer()->get_emails();
$emails['WC_Product_Vendors_Order_Email_To_Vendor']->trigger( $order );
}
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
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 );