Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
adicionar peso, largura, altura e comprimento no retorno da api do pedido do WooCommerce
<?php
function wc_add_rest_order_meta( $response, $post, $request ) {
foreach( $response->data['line_items'] as $item_id => $line_item ) {
if ( ! empty( $line_item['product_id'] ) ) {
$product_id = ! empty( $line_item['variation_id'] ) ? $line_item['variation_id'] : $line_item['product_id'];
$response->data['line_items'][ $item_id ]['weight'] = get_post_meta( $product_id, '_weight', true );
$response->data['line_items'][ $item_id ]['length'] = get_post_meta( $product_id, '_length', true );
$response->data['line_items'][ $item_id ]['width'] = get_post_meta( $product_id, '_width', true );
$response->data['line_items'][ $item_id ]['height'] = get_post_meta( $product_id, '_height', true );
}
}
return $response;
}
add_filter( 'woocommerce_rest_prepare_shop_order_object', 'wc_add_rest_order_meta', 9999, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.