3

I am updating a custom WooCommerce payment gateway.

I added the ability for a site admin to create an order on behalf of the buyer. I'm running into an issue displaying error messages.

wc_add_notice( __( 'Transaction Error: Could not find corporate account in Apruve.',
                'apruve-woocommerce' ),
                'error' );

When that code executes in the admin panel, it throws the following error.

Fatal error: Uncaught Error: Call to undefined function wc_add_notice()

My question is, how can I get access to that WooCommerce::Functions method in my own plugin?

Pro777
  • 1,684
  • 1
  • 18
  • 30
  • Possible duplicate of [Call a function of Woocommerce plugin from my plugin](https://stackoverflow.com/questions/32011391/call-a-function-of-woocommerce-plugin-from-my-plugin) – Charles Aug 29 '17 at 16:56
  • WC()->wc_add_notice() throw the same error: 'Call to undefined method WooCommerce::wc_add_notice() ' – Pro777 Aug 29 '17 at 17:01
  • If you look at the source for [WC()](https://docs.woocommerce.com/wc-apidocs/source-class-WooCommerce.html#386) on line 386 the file with the function you want is included. However it's only included if the request is from the frontend ([line 365](https://docs.woocommerce.com/wc-apidocs/source-class-WooCommerce.html#365)). You may need to call the `frontend_includes()` function prior to being able to run the `wc_add_notice()` function. – Charles Aug 29 '17 at 17:14
  • 1
    For admin notices you have [WC_Admin_Notices class](https://docs.woocommerce.com/wc-apidocs/class-WC_Admin_Notices.html) – LoicTheAztec Aug 29 '17 at 17:23
  • I'm able to add the message to WC_Admin_Notices, but they aren't being displayed back on the order edit page. – Pro777 Aug 29 '17 at 22:01

0 Answers0