Replace New order email recipient programmatically In Woocommerce

Viewed 1350

I am trying to change admins email based on the site language using the following code:

if ( !function_exists('my_email_heading_customisation_function_ent') ) { 

  function my_email_heading_customisation_function_ent( $recipient, $order  ) 
  {

    global $woocommerce;


    $page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
    if ( 'wc-settings' === $page ) {
      return $recipient; 
    }

    // just in case
    if ( ! $order instanceof WC_Order ) {
      return $recipient; 
    }


    $recipient = "some@email.cz";

    return $recipient;

  }

  add_filter('woocommerce_email_recipient_new_order', 'my_email_heading_customisation_function_ent', 10, 2);

}

But it doesn't work.

Any ideas how to solve this?

There a lot of thread about and some are really too old. I have checked the documentation and there is no mention of any change related to this hook. I have been pulling my hair over this.

1 Answers

Ok, thank you for your help. It turned out that the filter is working, the problem was cause by the HYYAN Woocommerce Polylang integration. I am gonna solve it with the plugin author...

Josif

Related