Advertisement
verygoodplugins

Untitled

Aug 28th, 2019
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. function add_product_name_field( $meta_fields ) {
  2.  
  3.     $meta_fields['product_name'] = array( 'label' => 'Last Product Purchased', 'group' => 'woocommerce' );
  4.  
  5.     return $meta_fields;
  6.  
  7. }
  8.  
  9. add_filter( 'wpf_meta_fields', 'add_product_name_field' );
  10.  
  11. function get_product_data( $order_data, $order ) {
  12.  
  13.     foreach ( $order->get_items() as $item ) {
  14.  
  15.         $product_id = $item->get_product_id();
  16.  
  17.         $order_data['product_name'] = get_the_title( $product_id );
  18.  
  19.     }
  20.  
  21.     return $order_data;
  22.  
  23. }
  24.  
  25. add_filter( 'wpf_woocommerce_customer_data', 'get_product_data', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement