1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* * Add a referanse field to the Order API response. */ function prefix_wc_rest_prepare_order_object( $response, $object, $request ) { // Get the value $referanse_meta_field = ( $value = get_post_meta($object->get_id(), '_billing_referanse', true) ) ? $value : ''; $response->data['referanse'] = $referanse_meta_field; return $response; } add_filter( 'woocommerce_rest_prepare_shop_order_object', 'prefix_wc_rest_prepare_order_object', 10, 3 ); /* * Legacy API * Add a referanse field to the Order API response. */ function prefix_wc_api_order_response( $order_data ) { // Get the value $referanse_meta_field = ( $value = get_post_meta($order_data['id'], '_billing_referanse', true) ) ? $value : ''; $order_data['referanse'] = $referanse_meta_field; return $order_data; } add_filter( 'woocommerce_api_order_response', 'prefix_wc_api_order_response', 10, 1 ); |
Tag Archives: REST API
WooCommerce REST API – Import products from JSON
I had a task to create a PHP script to import simple and variable products from JSON file using the WooCommerce REST API. Thought it might be worth sharing with others because I couldn’t find much information about products import from JSON using the API.