I have already used WooCommerce api on a specific page in practice. Understood with how the request path should look. If the page has such a path https://site.com/page , then it’s enough for me to make such a query path /../products , but what can I do if I cannot be sure which page will be is open? For example: in the case where the code is in the function.php file

I have a function that should be attached to the hook, but I don’t know how to specify the correct query path inside this function.

 function test_callback($order_id, $old_status, $new_status) { if( $new_status == "processing" ) { var_dump($woocommerce->get("/orders/$order_id")); //неправильный путь } } add_action( 'woocommerce_order_status_changed', 'test_callback', 10, 3); 

Perhaps what I want to do is a more elegant way, in any case I would like to know how this could be implemented.

    1 answer 1

    You argue with the wrong categories. What page? What does the page have to do with it? The woocommerce_order_status_changed hook woocommerce_order_status_changed triggered when the order status changes. This can happen when you pay, but no page is open at all! The bank gateway sends an HTTP POST request to the site, this request is processed by WooCommerce, and the hook is triggered. There is no interaction with the client’s browser. But the hook in functions.php will work, because this file is always loaded.

    To access the order in your code, you should use the wc_get_order() function:

     function test_callback( $order_id, $old_status, $new_status ) { if ( 'processing' === $new_status ) { $order = wc_get_order( $order_id ); // Вы можете использовать var_dump() если смена статуса вызвана вашими действиями // или вывести $order в лог-файл, если статус изменяется работой фоновых запросов (в бэкенде) } } add_action( 'woocommerce_order_status_changed', 'test_callback', 10, 3 );