Advertisement
majeedraza

WooCommerce - Add meta to cart, checkout and order

Jan 26th, 2018
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2.   // show the custom meta data on the cart and checkout pages
  3.   add_filter( 'woocommerce_get_item_data', 'tp_get_custom_item_data', 10, 2 );
  4.   function tp_get_custom_item_data( $item_data, $cart_item ) {
  5.     if( isset( $cart_item['size'] ) ) {  
  6.       $item_data[] = array( 'name' => 'Size', 'value' => $cart_item['size'] );
  7.     }
  8.     return $item_data;
  9.   }
  10.  
  11.   // add custom meta to order
  12.   // nb action 'woocommerce_add_order_item_meta' is deprecated
  13.   add_action( 'woocommerce_new_order_item', 'tp_add_custom_meta_to_order', 99, 3 );
  14.   function tp_add_custom_meta_to_order( $item_id, $item, $order_id ) {
  15.     if( isset( $item->legacy_values['size'] ) ) {
  16.       wc_add_order_item_meta( $item_id, 'Size', $item->legacy_values['size'] );
  17.     }
  18.   } // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement