• Resolved radial

    (@radial)


    On the Receipt, under or near the Payment Method section I would like to add the payment date, payment amount, and transaction ID

    thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • moksha shah

    (@mokshasharmila13)

    Hi @radial,

    For adding add the payment date, payment amount, and transaction ID near or under the payment method, Please add the below code in your active theme’s functions.php file or use a plugin like Code Snippets:

    function example_custom_order_fields( $fields, $order ) {
        $new_fields = array();
    
            $new_fields['_invoice_date'] = array(
                'label' => 'Invoice Date:',
                'value' => date( 'Y-m-d H:s:i', current_time( 'timestamp' ) ),
            );
    
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'example_custom_order_fields', 10, 2 );

    Please let us know if you need any other help.

    Regards,Moksha.

    Thread Starter radial

    (@radial)

    Ok, here is the code that I came up with and this seems to work. I do wonder though, the payment amount is just the order total. I do not see a way to get the actual payment amount, isn’t it possible a customers payment is different than the payment amount. If anyone has any ideas maybe they can share. But this code is works. I also am setting the time zone of the date paid so I can easily see that, you can change it to what you want.

    function payment_info_custom_order_fields( $fields, $order ) {
        $new_fields = array();
    
        // Add the Transaction ID field
        $new_fields['_transaction_id'] = array(
            'label' => 'Transaction ID:',
            'value' => $order->get_transaction_id(),
        );
    
        // Add the Date Paid field with the desired format 'Month day, year'
        $date_paid = $order->get_date_paid();
        if ( $date_paid ) {
            // Convert the date to Eastern Time (ET)
            $date_paid_object = new DateTime( $date_paid, new DateTimeZone( 'UTC' ) );
            $date_paid_object->setTimezone( new DateTimeZone( 'America/New_York' ) );
            $date_paid_formatted = $date_paid_object->format( 'F j, Y' );
        } else {
            $date_paid_formatted = '';
        }
        $new_fields['_date_paid'] = array(
            'label' => 'Date Paid:',
            'value' => $date_paid_formatted,
        );
    
        // Add the Payment Amount field
        $new_fields['_payment_amount'] = array(
            'label' => 'Payment Amount:',
            'value' => wc_price( $order->get_total() ), // Get the order total as payment amount and format it as a price.
        );
    
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'payment_info_custom_order_fields', 10, 2 );
    
    • This reply was modified 1 year, 4 months ago by radial.
    • This reply was modified 1 year, 4 months ago by radial.
    Thread Starter radial

    (@radial)

    I mean to say ?isn’t it possible a customers payment is different than the order amount. so i would like to get the actual payment amount.

    moksha shah

    (@mokshasharmila13)

    Hi @radial,

    Good to know that your problem is resolved. For the payment amount we are sharing the code link please check whether it works for you.

    Link:- https://woocommerce.github.io/code-reference/namespaces/default.html#function_wc_get_customer_total_spent

    It would be great if you can give a review for the plugin & the support on https://www.ads-software.com/support/plugin/woocommerce-delivery-notes/reviews/#new-post. That would be very helpful.

    Please Feel free to let us know if you need any help 

    Regards,Moksha.

    Thread Starter radial

    (@radial)

    marking closed, fixed thx

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add Payment details to Receipt’ is closed to new replies.