0

I have a woocommerce plugin and it provides an API url ?wc-api=myplugin.

The plugin adds a new email also.

function add_newstatus_woocommerce_email( $email_classes ) {
  require( 'emails/class-newstatus-email.php' );
  $email_classes['WC_Simplepay_Success_Email'] = new WC_Simplepay_Success_Email();
  return $email_classes;
}
add_filter( 'woocommerce_email_classes', 'add_newstatus_woocommerce_email' );

In emails/class-wc-simplepay-success-email.php I add an action in the constructor.

add_action( 'woocommerce_order_status_newstatus', array( $this, 'trigger' ) );

How can I use do_action to run this action from the plugin file? This does not seems to work. I guess it does not see that action.

do_action('woocommerce_order_status_newstatus');
7
  • is the file emails/class-wc-simplepay-success-email.php definitely being included, and included in time before the action hook fires?
    – Paul G.
    Jun 16, 2021 at 11:47
  • I think yes. The action is triggered when I do a change on the admin area, but not by the API call.
    – rrd
    Jun 16, 2021 at 11:49
  • so if you've confirmed the current setup is working as-is for 1 scenario, but not for the other, then it's likely the file isn't being included during a rest api call. Are you providing the code that includes the file - why do you "think" it is being included?
    – Paul G.
    Jun 16, 2021 at 11:52
  • here is the full code of the 2 files: controlc.com/35db2a48
    – rrd
    Jun 16, 2021 at 11:52
  • @PaulG. the API call the same plugin file, so that is why I think it is included. The debugger also stops there if I add a breakpoint.
    – rrd
    Jun 16, 2021 at 11:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.