Woocommerce - remove scheduled email - wordpress

I have a plugin which help me to book events. I have integrated a mail scheduler for reminder emails & feedback emails.
On confirmed booking emails are scheduled for reminder as well as feedback. I have both options to define it globally as well as individually to each event. This class is adding actions for the scheduled emails.
class WooEvent_Reminder_Email {
public function __construct()
{
add_filter( 'exc_mb_meta_boxes', array($this,'email_reminder_metadata') );
// Schedule the event when the order is completed.
add_action( 'woocommerce_order_status_completed', array( $this, 'remind_email' ), 10, 1 );
add_action( 'woocommerce_order_status_completed', array( $this, 'remind_email_fb' ), 11, 1 );
// Trigger the email.
add_action( 'wooevent_email_reminder', array( &$this, 'send_mail' ),10,4 );
add_action( 'wooevent_email_reminder_2', array( $this, 'send_mail' ),10,4 );
add_action( 'wooevent_email_reminder_3', array( $this, 'send_mail' ),10,4 );
add_action( 'wooevent_email_reminder_feedback', array( $this, 'send_mail_fb' ),10,3);
// send email to attendee
add_action( 'we_send_email_reminder', array( &$this, 'send_mail_attendee' ),10,1 );
}
Now, due to some reasons the event is not happening and I have created one more category for products "event-deactivated". If this category, I want to disable the event as well as want to remove all further email actions (i.e. no more notifications to the customer). For this objective, I am running this code:
add_filter('woocommerce_is_purchasable', 'nms3_catalog_mode_on_for_product', 10, 2 );
function nms3_catalog_mode_on_for_product( $is_purchasable, $product ) {
global $WooEvent_Reminder_Email;
if( has_term( 'seminar-deaktiviert', 'product_cat', $product->get_id() ) ) {
// you can set multiple conditions here
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Trigger the email.
remove_action( 'woocommerce_order_status_completed', array( $WooEvent_Reminder_Email, 'remind_email' ), 10, 1 );
remove_action( 'woocommerce_order_status_completed', array( $WooEvent_Reminder_Email, 'remind_email_fb' ), 11, 1 );
remove_action( 'wooevent_email_reminder', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
remove_action( 'wooevent_email_reminder_2', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
remove_action( 'wooevent_email_reminder_3', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
remove_action( 'wooevent_email_reminder_feedback', array( $WooEvent_Reminder_Email, 'send_mail_fb' ), 10, 1 );
// send email to attendee
remove_action( 'we_send_email_reminder', array( &$WooEvent_Reminder_Email, 'send_mail_attendee' ),10,1 );
return false;
}
return $is_purchasable;
}
With which action/filter, I should use the above or any modifications.
I am able to disabled the event on the basis of category, but already scheduled email are still queued up.
Any suggestions or help will be appreciated.
Thanks

Related

Cancel all user orders on subscription cancelled/expired

I want to develop a setup/code in which all the orders made by the user gets cancelled when the his subscription gets cancelled or expired. I am using Wordpress, Woocommerce and Woocommerce Subscriptions plugin.
I am trying to do by using something like this:
function my_cancelled_subscription( $user_id, $subscription_key ) {
//what code should I use here????
}
add_action( 'woocommerce_subscription_status_cancelled', 'my_cancelled_subscription', 10, 2 );
Please help mee.....
I figured it out..........
function my_cancelled_subscription( $subscription ) {
$order_id = $subscription->get_parent_id();
$order = wc_get_order( $order_id );
$user_id = $order->get_user_id();
$order->update_status( 'cancelled' );
$args = array(
'customer_id' => $user_id,
'status' => 'wc-completed',
);
$arrorders = wc_get_orders( $args );
foreach ($arrorders as $ord) {
$ord->update_status( 'cancelled' );
}
}
add_action( 'woocommerce_subscription_status_cancelled', 'my_cancelled_subscription' );

Activating a plugin from inside Woocomerce single product page using a check box

i am looking for a way to activate a plugin from a woocommerce single product page, the plugin displays shipping countdown for delivery but its not relevant to all products and i would like to use a check box inside the single product to turn on and of per product page
the plugin is being activated across all products at the moment using the add action from theme mod to be able to change the position this really is not necessary so if need this could be removed and replaced with some other way on activating the plugin on a per product basis
$scfwc_render_location = get_theme_mod( 'scfwc_render_location');
switch ( $scfwc_render_location ) :
case 'scfwc_after_heading' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 6 );
break;
case 'scfwc_after_price' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 11 );
break;
case 'scfwc_after_short_desc' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 21 );
break;
case 'scfwc_after_add_cart' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 31 );
break;
case 'scfwc_after_single_product_summary' :
add_action( 'woocommerce_product_thumbnails', array( $this, 'scfwc_html_product' ), 30 );
break;
endswitch;
I don't know what class $this is referencing, or how to get an instance of it, so this is pseudo-code. But once you have the meta field displaying and saving in the admin, you can use the meta field's value to conditionally add the scfwc_html_product() method.
function kia_conditionally_add_countdown() {
global $product;
if( $product->get_meta( '_show_countdown', true ) ) {
$my_class = somehow_get_instance_of_class();
add_action( 'woocommerce_single_product_summary', array( $my_class, 'scfwc_html_product' ), 11 );
}
}
add_action( 'woocommerce_before_single_product_summary', 'kia_conditionally_add_countdown' );
This doesn't take into account the theme mod and just hard-codes the priority/position. You could add support for the theme_mod inside the conditional logic, if needed.

How to remove actions from Yoast SEO plugin

I need to remove the actions that Yoast SEO has added. This is my code:
function remove_actions() {
// deregister all not more required tags
remove_action( 'wp_head', '_wp_render_title_tag', 50 );
remove_action( 'wp_head', array( 'WPSEO_Frontend', 'test123' ), 50 );
remove_action( 'wp_head', array( 'WPSEO_Frontend', 'front_page_specific_init' ), 50 );
remove_action( 'wp_head', array( 'WPSEO_Frontend', 'head' ), 50 );
remove_action( 'wpseo_head', array( 'WPSEO_Frontend', 'head' ), 50 );
remove_action( 'wpseo_head', array( 'WPSEO_Frontend', 'metadesc' ), 50 );
remove_action( 'wpseo_head', array( 'WPSEO_Frontend', 'robots' ), 50 );
remove_action( 'wpseo_head', array( 'WPSEO_Frontend', 'metakeywords' ), 50 );
remove_action( 'wpseo_head', array( 'WPSEO_Frontend', 'canonical' ), 50 );
remove_action( 'wpseo_head', array( 'WPSEO_Frontend', 'adjacent_rel_links' ), 50 );
remove_action( 'wpseo_head', array( 'WPSEO_Frontend', 'publisher' ), 50 );
}
add_action( 'wp_head', 'remove_actions', 1000 );
This code does not remove the actions. What is wrong? How can I remove the actions successfully?
Consider these notes from the remove_action Documentation:
You may need to prioritize the removal of the action to a hook that occurs after the action is added.
You cannot successfully remove the action before it has been added.
You also cannot remove an action after it has been run.
To remove an action the priority must match the priority with with the function was originally added.
In your case, I believe several of these issues (especially #3 and #4) are causing problems:
First, the priority on your add_action is too high. By setting it this high, it's running after all of the Yoast wp_head actions are run. Instead, hook into the same action you want to remove, but with a very low number, such as -99999, to cause it to run before the Yoast actions are run. (Further, I've broken into two functions, just to be sure they are run at the correct time - one for each action - wp_head and wpseo_head).
Second, your priorities do not match the priorities in the Yoast code. I've dug through all the Yoast code to find all of these actions and documented / corrected in the code below - and I can tell you for example the metakeywords hook in Yoast code is 11, so your remove_action (with priority 40) will not work.
Finally, Yoast adds these actions to $this (an instantiated version of the WPSEO_Frontend class), not static version of the class methods. This means that remove_action is not able to find them based on the function array(WPSEO_Frontend, head), for example. Instead, you need to load the instantiated version of Yoast, and pass that in to the remove_action functions.
Documented code below:
// Remove ONLY the head actions. Permits calling this at a "safe" time
function remove_head_actions() {
// not Yoast, but WP default. Priority is 1
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
// If the plugin isn't installed, don't run this!
if ( ! is_callable( array( 'WPSEO_Frontend', 'get_instance' ) ) ) {
return;
}
// Get the WPSEO_Frontend instantiated class
$yoast = WPSEO_Frontend::get_instance();
// removed your "test" action - no need
// per Yoast code, this is priority 0
remove_action( 'wp_head', array( $yoast, 'front_page_specific_init' ), 0 );
// per Yoast code, this is priority 1
remove_action( 'wp_head', array( $yoast, 'head' ), 1 );
}
function remove_wpseo_head_actions() {
// If the Yoast plugin isn't installed, don't run this
if ( ! is_callable( array( 'WPSEO_Frontend', 'get_instance' ) ) ) {
return;
}
// Get the Yoast instantiated class
$yoast = WPSEO_Frontend::get_instance();
remove_action( 'wpseo_head', array( $yoast, 'head' ), 50 );
// per Yoast code, this is priority 6
remove_action( 'wpseo_head', array( $yoast, 'metadesc' ), 6 );
// per Yoast code, this is priority 10
remove_action( 'wpseo_head', array( $yoast, 'robots' ), 10 );
// per Yoast code, this is priority 11
remove_action( 'wpseo_head', array( $yoast, 'metakeywords' ), 11 );
// per Yoast code, this is priority 20
remove_action( 'wpseo_head', array( $yoast, 'canonical' ), 20 );
// per Yoast code, this is priority 21
remove_action( 'wpseo_head', array( $yoast, 'adjacent_rel_links' ), 21 );
// per Yoast code, this is priority 22
remove_action( 'wpseo_head', array( $yoast, 'publisher' ), 22 );
}
Final Notes:.
Remove the WPSEO_Frontend::head action is very heavy handed. This will yank a whole host of other things you probably don't want removed.
Second, It's probably better to modify the output of these actions, rather than removing them completely.
For example,
add_action('wpseo_metakeywords', 'your_metakeywords_function');
function your_metakeywords_function( $keywords ) {
// modify the keywords as desired
return $keywords;
}
Many of these actions have filters and output can be removed by returning false.
// Removes 'meta name="description"' tag from output
add_filter( 'wpseo_metadesc', 'my_custom_metadesc' );
function my_custom_metadesc() {
return false;
}
In some cases like WPSEO_Opengraph there's a filter pattern: wpseo_og_ + property name with underscores instead of colons.
// Filters '<meta property="article:tag" content="Foo" />'
add_filter( 'wpseo_og_article_tag', 'my_custom_article_tag' );

Menus panel in wordpress customizer

I am trying to remove Menus panel in wordpress customizer using below code but its not working.Someone please guide me.Thanks
$wp_customize->remove_panel( 'nav_menus' );
There are 2 Trac tickets that govern this issue. The complete solution to this is
add_action( 'customize_register', function( $wp_customize ) {
/** #var WP_Customize_Manager $wp_customize */
remove_action( 'customize_controls_enqueue_scripts', array( $wp_customize->nav_menus, 'enqueue_scripts' ) );
remove_action( 'customize_register', array( $wp_customize->nav_menus, 'customize_register' ), 11 );
remove_filter( 'customize_dynamic_setting_args', array( $wp_customize->nav_menus, 'filter_dynamic_setting_args' ) );
remove_filter( 'customize_dynamic_setting_class', array( $wp_customize->nav_menus, 'filter_dynamic_setting_class' ) );
remove_action( 'customize_controls_print_footer_scripts', array( $wp_customize->nav_menus, 'print_templates' ) );
remove_action( 'customize_controls_print_footer_scripts', array( $wp_customize->nav_menus, 'available_items_template' ) );
remove_action( 'customize_preview_init', array( $wp_customize->nav_menus, 'customize_preview_init' ) );
}, 10 );
More details:
https://core.trac.wordpress.org/ticket/33552
https://core.trac.wordpress.org/ticket/33411
In the old versions of wordpress (<4.3) this worked, but not now:
function your_customizer( $wp_customize ) {
$wp_customize->remove_panel( 'widgets' );
}
add_action( 'customize_register', 'your_customizer' );
Thank you dingo_d, that worked for me too.
Incidentally, $wp_customize->remove_panel('widgets); still works in Wordpress v. 4.5.1

Adding a receipt page on woocommerce

I am developing a payment gateway for woocommerce.
I read many tutorial of how I can manage to do it but I can't figure out what this line of code mean:
add_action( 'woocommerce_receipt_paypal', array( $this, 'receipt_page' ) );
Especially, there is no function called woocommerce_receipt_paypal and how can I reproduce it in my plugin.
You have to replace
add_action( 'woocommerce_receipt_paypal', array( $this, 'receipt_page' ) );
with
add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'receipt_page' ) );
where id is the one you set in __construct() function.

Resources