Last active
June 20, 2022 14:47
-
-
Save scottopolis/1fa6400ddf0be63b40d3caa9985d3646 to your computer and use it in GitHub Desktop.
Modify WooCommerce REST API Product Response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add this code to a custom plugin | |
add_filter( 'woocommerce_rest_prepare_product_object', 'wc_app_add_custom_data_to_product', 10, 3 ); | |
// filter the product response here | |
function wc_app_add_custom_data_to_product( $response, $post, $request ) { | |
// in this case we want to display the short description, so we copy it over to the description, which shows up in the app | |
$response->data['description'] = $response->data['short_description']; | |
return $response; | |
} |
Thanks! Works great with Woocommerce 4.7.0 on WP 5.5.3
Does it still work? I have added in my function.php but not getting any changes.
@naumanahmed19 it looks like the correct filter now includes object woocommerce_rest_prepare_product_object
http://hookr.io/actions/woocommerce_rest_prepare_product_object/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally I had found the correct way for modifying the WC product REST API response.
I were missing "_object" after "woocommerce_rest_prepare_product" in the name of the filter.
Thanks!