-
-
Save abegit/74e691d877cadc37d7b6 to your computer and use it in GitHub Desktop.
function mysite_pending($order_id) { | |
error_log("$order_id set to PENDING", 0); | |
} | |
function mysite_failed($order_id) { | |
error_log("$order_id set to FAILED", 0); | |
} | |
function mysite_hold($order_id) { | |
error_log("$order_id set to ON HOLD", 0); | |
} | |
function mysite_processing($order_id) { | |
error_log("$order_id set to PROCESSING", 0); | |
} | |
function mysite_completed($order_id) { | |
error_log("$order_id set to COMPLETED", 0); | |
} | |
function mysite_refunded($order_id) { | |
error_log("$order_id set to REFUNDED", 0); | |
} | |
function mysite_cancelled($order_id) { | |
error_log("$order_id set to CANCELLED", 0); | |
} | |
add_action( ‘woocommerce_order_status_pending’, ‘mysite_pending’); | |
add_action( ‘woocommerce_order_status_failed’, ‘mysite_failed’); | |
add_action( ‘woocommerce_order_status_on-hold’, ‘mysite_hold’); | |
// Note that it’s woocommerce_order_status_on-hold, not on_hold. | |
add_action( ‘woocommerce_order_status_processing’, ‘mysite_processing’); | |
add_action( ‘woocommerce_order_status_completed’, ‘mysite_completed’); | |
add_action( ‘woocommerce_order_status_refunded’, ‘mysite_refunded’); | |
add_action( ‘woocommerce_order_status_cancelled’, ‘mysite_cancelled’); |
I believe to activate the error logs you need to add a few lines to wp-config.php
so that it starts capturing all the errors.
https://stackoverflow.com/a/24330117
Add these lines to wp-config.php
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );
this should activate the debug log and save to the default location .../wp-content/debug.log
WP_DEBUG — turns the debugging features ON/OFF
WP_DEBUG_DISPLAY — sets to display the errors on your website at exact moment they happen, even if logged off
WP_DEBUG_LOG — sets to print out the errors to file .../wp-content/debug.log
This $order_id that is passed as param. is dynamic? for exemple, if i make an order with id = 30, this $order_id will be the 30?
Just to note that your ‘ should be '.
A small difference but a crucial one.
Thanks for the script! <3
Where does it get $order_id from ? I have put this in my functions.php, getting the error: Undefined variable: order_id.
Thanks
Where does it get $order_id from ? I have put this in my functions.php, getting the error: Undefined variable: order_id.
Thanks
I am also wondering many times ;) This error only comes from IDE, but I think $order_id come from deeper...
@michaelbarley @smiell
technically the add_action() is hooking into an existing do_action() which has multiple parameters.
These are:
- hook name,
- callback function,
- priority,
- accepted arguments.
Because the default priority is 10 and the accepted argument is 1 for any 'add_action', we do not have to specify these if we are not changing them. For this reason, only two parameters are being specified in the above actions (hook name and callback).
That default 'argument' in the above hooks is $order_id.
If you wish for your IDE to stop showing this as an error you can include WooCommerce in it's PHP frameworks, allowing your IDE to see the WooCommerce code and spot that this is not an error.
@michaelbarley @smiell technically the add_action() is hooking into an existing do_action() which has multiple parameters. These are:
- hook name,
- callback function,
- priority,
- accepted arguments.
Because the default priority is 10 and the accepted argument is 1 for any 'add_action', we do not have to specify these if we are not changing them. That default argument in the above hooks is $order_id.
If you wish for your IDE to stop showing this as an error you can include WooCommerce in it's PHP frameworks, allowing your IDE to see the WooCommerce code and spot that this is not an error.
Thank you for your explanation ;)
where does those logs save ?