Tell us what you are trying to do?
I'm trying to expose / add custom taxonomies to the WC REST API, then updating said taxonomy through the WC REST API.
Is there any documentation that you are following?
Not really, using php code to expose the taxonomy and then my own JS dev for updating products through the WC REST API.
The taxonomy appears well exposed when using GET to the API, as follows:
"marca": [
{
"id": 67,
"name": "Frasle",
"slug": "frasle"
}
]
Correctly sends, ID, name and slug, don't need anything else, not even slug actually but whatever.
When I try to update the custom taxonomy I get the following log:
Exception: Request failed for hidden link returned code 500. Truncated server response: {"code":"internal_server_error","message":"<p>Ha habido un error cr\u00edtico en esta web.<\/p>
Basically a 500 critical error.
Already having admin user+pw from another ticket, I'm sure you can get testing API keys.
It can be tested with Insomnia / Postman.
Thank you!
Hello,
There should be some PHP errors in your website, please try theese:
1) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, deactivate all custom PHP/JS code snippets, and test again
2) Also check if there is any PHP error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/
section "PHP Debugging"
It appears the issue is with the php code that is exposing the custom taxonomy to the rest API.
2022-01-24T14:00:38+00:00 CRITICAL Uncaught Error: Call to undefined method WC_Product_Simple::ID() in /home/crudricc/public_html/wp-content/themes/astra-child/functions.php:95
Stack trace:
#0 /home/crudricc/public_html/wp-includes/rest-api/endpoints/class-wp-rest-controller.php(461): product_update_callback(Array, Object(WC_Product_Simple), 'marca', Object(WP_REST_Request), 'product')
#1 /home/crudricc/public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php(245): WP_REST_Controller->update_additional_fields_for_object(Object(WC_Product_Simple), Object(WP_REST_Request))
#2 /home/crudricc/public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-controller.php(269): WC_REST_CRUD_Controller->update_item(Object(WP_REST_Request))
#3 /home/crudricc/public_html/wp-includes/rest-api/class-wp-rest-server.php(1140): WC_REST_Controller->batch_items(Object(WP_REST_Request))
#4 /home/crudricc/public_html/wp-includes/rest-api/class-wp-rest-server.php(987): WP_ en /home/crudricc/public_html/wp-content/themes/astra-child/functions.php en la línea 95
The code itselft:
https://pastebin.com/ps53zZ9H
To be prices, since it calls line 95, it would be specifically:
$postId = $post->ID();
Not sure why but apparently the post id is undefined in a way?
It is a custom PHP codes problem, please try to modify this line from:
$postId = $post->ID();
To:
$postId = $post[ 'id' ];
And test again
I put the modificaction, still shows, but still throws a 500 critical error.
I wonder if it could be related to the fact Toolset in general throws some critical error, when for instance I try to use the customizer
Had nothing to do with that, that was due to Elementor 3.5.x, a rollback made the customizer work fine.
Thanks for sharing the problem source, since it is Elementor 3.5.x issue, which is out the range of Toolset support, please check it with Elementor support, and close this thread, thanks
No, that isn't the issue. Elementor made the customizer work, I was just spitballing what could be the issue.
The expose of the taxonomy still doens't work when trying to use the REST API, doubt it has anything to do with Elementor.
Since it is a custom PHP codes problem, I suggest you try to fix your custom PHP codes by following WP document and Woocommerce document:
https://developer.wordpress.org/reference/functions/register_rest_field/
hidden link
And I have searched it in google, found some related threads, for example:
https://stackoverflow.com/questions/62664811/add-custom-taxonomy-term-in-woocommerce-rest-api
If you still need assistance for it, please provide a test site with the same problem, fill below private message box with login details, I need a live website to test and debug
I have tried the credentials you provide above, but get below error message:
Error: la contraseña que has introducido para el nombre de usuario toolsetHelp no es correcta.
Please check it, make sure it is an valid admin account, thanks
Sorry, it autocompleted wrongly, the password is updated.
It is a Woocommerce issue, you can follow the thread I mentioned above to modify your custom PHP codes.
I have done below modifications in your website, replace this line from:
$postId = $post[ 'id' ];
With:
$postId = $post->get_id();
Please test again, check if it is fixed.
My issue is resolved now. Thank you!