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 hidden or 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@naumanahmed19 it looks like the correct filter now includes object
woocommerce_rest_prepare_product_object
http://hookr.io/actions/woocommerce_rest_prepare_product_object/