0

I have a WooCommerce store and it as usually saves Order Data in WordPress database. I have created a separate database order_master in which I want to store the WooCommerce Order.

For this, I have defined a separate database in wp-config as:

$host = 'localhost';
$user = 'root';
$pass = '';
$db   = 'order_master';

So, Can an external database could be used to save WooCommerce Order details? If yes, Then I would really appreciate any help regarding this.

  • Do you want to save wp orders data in to another database? – dipmala Dec 03 '18 at 10:40
  • 2
    but... they have their own table? is that not enough? Getting it to work the other woocommerce functions, like get_order(); etc, might not be easy. – Stender Dec 03 '18 at 10:44
  • 1
    Yeah, It stores in WordPress database but I want to save details on an external server MySQL database. –  Dec 03 '18 at 10:46
  • you could hook in on the order functions (save, update etc) and send the details to your other DB as well as the native one, but then you have it in two tables/DBs – Stender Dec 03 '18 at 10:54
  • which hook could be used to do this? –  Dec 03 '18 at 10:58
  • all of the hooks are listed here : https://docs.woocommerce.com/wc-apidocs/hook-docs.html – Stender Dec 03 '18 at 11:07
  • but I would look into `woocommerce_update_order` and `woocommerce_new_order` - – Stender Dec 03 '18 at 11:08
  • Keep in mind, I don't know what data you require in you new db - There might be a lot of work ahead for you! – Stender Dec 03 '18 at 11:09
  • I need only `order-id` and `amount` to be saved –  Dec 03 '18 at 11:10
  • http://hookr.io/actions/woocommerce_new_order/ might be easier to understand than the docs – Stender Dec 03 '18 at 11:12
  • example on how to call it, has been answered here : https://stackoverflow.com/questions/37868183/woocommerce-new-order-action-get-order-information – Stender Dec 03 '18 at 11:14

0 Answers0