• Resolved maorpe

    (@maorpe)


    I need to show email and phone number for export orders in woocommerce. I have this code for export weight. Which code can I use to show email and phone shipping?

    /**
     * Step 1. Add weight to line item data
     *
     * @param array $line_item the original line item data
     * @param array $item the item's order data
     * @param object $product the \WC_Product object for the line
     * @param object $order the \WC_Order object being exported
     * @return array the updated line item data
     */
    function sv_wc_csv_export_add_weight_to_line_item( $line_item, $item, $product, $order ) {
    
    	$new_item_data = array();
    
    	foreach ( $line_item as $key => $data ) {
    
    		$new_item_data[ $key ] = $data;
    
    		if ( 'sku' === $key && $product ) {
    			$new_item_data['weight'] = wc_format_decimal( $product->get_weight(), 2 );
    		}
    	}
    
    	return $new_item_data;
    }
    add_filter( 'wc_customer_order_export_csv_order_line_item', 'sv_wc_csv_export_add_weight_to_line_item', 10, 4 );

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author FAKTOR VIER

    (@faktorvier)

    Hi @maorpe

    Thats how you can get the shipping phone:

    $order->get_shipping_phone();

    and thats how you can get the shipping email:

    get_post_meta($order->get_id(), '_shipping_email', true);

    I dont quite get the the code you’ve posted above and in wat format the phone number and email should be added to the array, because it looks like you have to add the phone and email for every product position? I dont know if this is the right solution, feel free to fix it according to your needs:

    
    function sv_wc_csv_export_add_weight_to_line_item( $line_item, $item, $product, $order ) {
    
    	$new_item_data = array();
    
    	foreach ( $line_item as $key => $data ) {
    
    		$new_item_data[ $key ] = $data;
    
    		if ( 'sku' === $key && $product ) {
    			$new_item_data['weight'] = wc_format_decimal( $product->get_weight(), 2 );
    			$new_item_data['shipping_phone'] = $order->get_shipping_phone();
    			$new_item_data['shipping_email'] = get_post_meta($order->get_id(), '_shipping_email', true);
    		}
    	}
    
    	return $new_item_data;
    }
    add_filter( 'wc_customer_order_export_csv_order_line_item', 'sv_wc_csv_export_add_weight_to_line_item', 10, 4 );
    
Viewing 1 replies (of 1 total)
  • The topic ‘show phone and mail shipping for export orders’ is closed to new replies.