Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.5 kB
5
Indexable
Never
add_filter('b2bking_quote_message_before_items', function($messagecart, $items, $user_id){

    ob_start();
    display_customer_order_history($user_id);
    $messagecart.= ob_get_clean();
    return $messagecart;
}, 10, 3);

function display_customer_order_history($user_id) {
    // Get all customer orders
    $customer_orders = wc_get_orders(array(
        'meta_key' => '_customer_user',
        'meta_value' => $user_id,
        'post_status' => array('wc-completed')
    ));

    // Start building the table
    echo '<table>';
    echo '<tr><th>Image</th><th>Title</th><th>Price</th><th>Quantity</th></tr>';

    // Loop through each customer order
    foreach ($customer_orders as $customer_order) {
        // Loop through each item in the order
        foreach ($customer_order->get_items() as $item_id => $item) {
            // Get the product object
            $product = $item->get_product();

            // Get product details
            $image = $product->get_image(); // Image HTML
            $title = $product->get_name(); // Product name
            $price = $product->get_price(); // Product price
            $quantity = $item->get_quantity(); // Quantity ordered

            // Output table row
            echo '<tr>
                    <td>'.$image.'</td>
                    <td>'.$title.'</td>
                    <td>'.$price.'</td>
                    <td>'.$quantity.'</td>
                  </tr>';
        }
    }

    echo '</table>';
}
Leave a Comment