Search code examples
phpwordpresswoocommercehook-woocommerceorders

Display Order total in WooCommerce order quick view


I want to display the order total in the order preview popup like the image below.

enter image description here


Solution

  • Based on Show used coupon in WooCommerce order quick view answer, You can use the following to add the order total to WooCommerce order quick view:

    // Add custom order data to make it accessible in Order preview template
    add_filter( 'woocommerce_admin_order_preview_get_order_details', 'admin_order_preview_add_order_total', 10, 2 );
    function admin_order_preview_add_order_total( $data, $order ) {
        $data['order_total'] = strip_tags( wc_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ) );
        return $data;
    }
    
    // Display The data in Order preview
    add_action( 'woocommerce_admin_order_preview_end', 'display_order_total_in_admin_order_preview' );
    function display_order_total_in_admin_order_preview(){
        // Call the stored value and display it
        echo '<div><table cellspacing="0" class="wc-order-preview-table"><thead><tr>
            <th class="wc-order-preview-table__column--total">' . __('Total') . '</th>
            <td class="wc-order-preview-table__column--total-amount">{{{data.order_total}}}</td>
        </tr></thead></table></div>';
    }
    

    Code goes in functions.php file of your child theme (or in a plugin). Tested and works.

    enter image description here