• Resolved lcameron

    (@lcameron)


    Hi, We have added a flexible field for shipping number at checkout in the billing section which works great, however we have a plugin (Delivery Drivers for WooCommerce Pro) that we run reports through for each delivery day/week that includes address, phone number etc. We have tried adding the shipping phone number as below to the code in our child’s functions.php, however the shipping number will not show in the report. The Delivery Drivers for WooCommerce Pro support team have been attempting to help resolve, but are unable to get the field to show using $value->_billing_shipping_phone;. Any help would be appreciated as we need the shipping number to appear for our drivers in the reports.

    CODE
    // Add shipping number to Delivery report

    add_filter( ‘orddd_print_columns’, ‘orddd_print_columns’ );
    function orddd_print_columns( $columns ) {
    $columns = ”
    <tr>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Order ID’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Products’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Billing Address’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Shipping Address’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Shipping Method’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( get_option( ‘orddd_location_field_label’ ), ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Delivery Date’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Delivery Time’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Order Date’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Phone Number’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Order Note’, ‘order-delivery-date’ ).”</th>
    <th style=’border:1px solid black;padding:5px;’>”.__( ‘Shipping Phone’, ‘order-delivery-date’ ).”</th>
    </tr>”;
    return $columns;
    }

    add_filter( ‘orddd_print_rows’, ‘orddd_print_rows’, 10, 2 );
    function orddd_print_rows( $rows, $data ) {
    $rows = ”;
    foreach ( $data as $key => $value ) {
    // Currency Symbol
    // The order currency is fetched to ensure the correct currency is displayed if the site uses multi-currencies
    $the_order = wc_get_order( $value->order_id );
    $currency = ( version_compare( WOOCOMMERCE_VERSION, “3.0.0” ) < 0 ) ? $the_order->get_order_currency() : $the_order->get_currency();
    $currency_symbol = get_woocommerce_currency_symbol( $currency );
    $rows .= “<tr>
    <td style=’border:1px solid black;padding:5px;’>” . $value->order_id . “</td>
    <td style=’border:1px solid black;padding:5px;’>”;
    foreach( $value->product_name as $id => $data ) {
    $rows .= $data[‘product’] . ” x ” . $data[‘quantity’].”<br>”;
    }
    $rows .= “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $value->billing_address . “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $value->shipping_address . “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $value->shipping_method . “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $value->pickup_location . “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $value->delivery_date . “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $value->delivery_time . “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $value->order_date . “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $the_order->get_billing_phone() . “</td>
    <td style=’border:1px solid black;padding:5px;’>” . $the_order->get_customer_note(‘view’) . “<td style=’border:1px solid black;padding:5px;’>” . $value->_billing_shipping_phone . “</td>
    </td>

    </tr>”;
    }
    return $rows;
    }

    // Add Phone Number for Delivery CSV format

    add_filter( ‘orddd_csv_data’, ‘orddd_csv_data’, 10, 2 );
    function orddd_csv_data( $csv, $report ) {
    $csv = ‘Order ID,Products,Billing Address,Shipping Address,Shipping Method,’ . __( get_option( ‘orddd_location_field_label’ ), ‘order-delivery-date’ ) . ‘,Delivery Date,Delivery Time,Order Date, Phone Number, Shipping Phone’;
    $csv .= “\n”;
    foreach ( $report as $key => $value ) {
    // Order ID
    $order_id = $value->order_id;
    $product_name = $value->product_name;
    $quantity = $value->quantity;
    $billing_address = $value->billing_address;
    $shipping_address = $value->shipping_address;
    $shipping_method = $value->shipping_method;
    $pickup_location = $value->pickup_location;
    $delivery_date = $value->delivery_date;
    $delivery_time = $value->delivery_time;
    $order_date = $value->order_date;
    $product_name = str_replace( ‘”‘, ‘””‘, $product_name );
    $the_order = wc_get_order( $value->order_id );
    $order = new WC_Order( $order_id );
    $phone = $order->get_billing_phone();
    $shipping_phone = $value->_billing_shipping_phone;

    if ( ‘product’ == $_GET[‘eventType’] ) {
    $break = ”;
    } else {
    $break = “\n”;
    }
    // Create the data row
    $csv .= $order_id . ‘,”‘;
    foreach ( $product_name as $id => $data ) {
    $name = str_replace( ‘
    ‘, “\n”, $data[‘product’] );
    $csv .= strip_tags( $name ) . ‘ x ‘ . $data[‘quantity’] . $break;
    }
    // Create the data row
    $csv .= ‘”,”‘ . $billing_address . ‘”,”‘ . $shipping_address . ‘”,”‘ . $shipping_method . ‘”,”‘ . $pickup_location . ‘”,”‘ . $delivery_date . ‘”,”‘ . $delivery_time . ‘”,”‘ . $order_date . ‘”,”‘ . $phone . ‘”‘ . $shipping_phone . ‘”‘;
    $csv .= “\n”;
    }
    return $csv;

    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Tomasz WP Desk

    (@tomaszwp)

    Hello @lcameron,

    If you would like to display a value of specific field entered by your customer in the checkout – use below PHP code:

    echo $order->get_meta( ‘meta_name’);

    To learn a meta name (the name that the field is written under in the database) – check the field configuration.

    Plugin Support Tomasz WP Desk

    (@tomaszwp)

    I am marking this topic as resolved as we have not received any new replies.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pulling field into reports’ is closed to new replies.