daily pastebin goal
51%
SHARE
TWEET

WooCommerce - Add meta to cart, checkout and order

lorro Jan 26th, 2018 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top