'remove_action'在woocommerce_email挂钩中的实时网站上不起作用

时间:2019-06-24 13:18:46

标签: php woocommerce

我有代码,因此可以手动更改WooCommerce订单状态,而无需向客户发送“订单已完成”通知。我只希望这种情况发生在我的用户名上。下面的代码在我的(本地)测试环境中可以很好地工作,但在我的实时网站上却什么也没做。

我添加了一个回显<pre>';var_dump($user);die('</pre>');,以测试该钩子是否完全运行,并且if语句是否正常运行,是否按预期运行,只是remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );没有运行。

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );

function unhook_those_pesky_emails( $email_class ) {

  $user = wp_get_current_user();
//  echo '<pre>';var_dump($user);die('</pre>');

    if ( is_admin() && $user && isset($user->user_login) && 'Martijn' == $user->user_login) {

        // New order emails
        remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
        remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
        remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
        remove_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
        remove_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
        remove_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );

        // Processing order emails
        remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
        remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );

        // Completed order emails
        remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );

    }
}

您知道为什么此代码可能在我的本地网站上有效但在我的实时网站上无效吗?也许有些矛盾。据我所知,两个站点都使用相同的代码/插件运行。

0 个答案:

没有答案