Skip to content

Instantly share code, notes, and snippets.

@davidchc
Created March 10, 2020 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidchc/ce5b1a95da6336df5332b85d47fdd22e to your computer and use it in GitHub Desktop.
Save davidchc/ce5b1a95da6336df5332b85d47fdd22e to your computer and use it in GitHub Desktop.
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