WordPress.org

Forums

WooCommerce Print Invoice & Delivery Note
Hook to show Coupon Code on Invoice (7 posts)

  1. eberswine
    Member
    Posted 11 months ago #

    I think I am close?

    I am trying to show the "coupon code" used underneath the "Cart Discount" amount row on the invoice.

    function my_custom_order_fields( $fields, $order ) {
        $new_fields = array();
    
        if( get_post_meta( $order->id, 'woocommerce_coupon_code', true ) ) {
            $new_fields['woocommerce_coupon_code'] = array(
                'label' => 'Coupon Code 1',
                'value' => get_post_meta( $order->id, 'woocommerce_coupon_code', true )
            );
        }
    
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'my_custom_order_fields', 10, 2 );

    https://wordpress.org/plugins/woocommerce-delivery-notes/

  2. Bozz
    Member
    Posted 10 months ago #

    Great plugin! I'm very much interested in sorting out a solution to this myself, or better yet seeing the coupon code printed automatically on the default templates.

  3. eberswine
    Member
    Posted 9 months ago #

    I am so close!!! I think I just need a few small edits!! Can anyone point me in the right direction ?

    Thanks! What a great plugin! 5 stars!

  4. eberswine
    Member
    Posted 8 months ago #

    Still trying to get this to show up. I just updated to the latest release, but still no "coupon code" on PDF invoice, just the $dollar amount...

  5. louisp56
    Member
    Posted 7 months ago #

    Has anyone managed to do this yet? Really need to show coupon code on the packing slip!

  6. eberswine
    Member
    Posted 7 months ago #

    Ok, here is what I did to accomplish this.

    ** disclaimer ** There is much better ways to achieve this. This is very straight forward using the "template" method

    Made a template in your theme folder ( copied the one in the plugin folder )

    /woocommerce/print-order/print-content.php

    All I added was a quick query to grab the "coupon code" if it exists:

    At the end of the <table> I inserted this code:

    <?php 	if( $order->get_used_coupons() ) {
    $coupons_count = count( $order->get_used_coupons() );
    echo '<div style="padding:5px; background-color: #eaeaea;"><h4 style="margin-top:10px;">' . __('Coupons used') . ' (' . $coupons_count . ')</h4>';
    echo '<p><strong>' . __('Coupons used') . ':</strong> ';
    $i = 1;
    $coupons_list = '';
    foreach( $order->get_used_coupons() as $coupon) {
    $coupons_list .= $coupon;
    if( $i < $coupons_count )
    $coupons_list .= ', ';
    $i++;
    }
    echo '<p style="padding:4px;"><strong>Coupons used (' . $coupons_count . ') :</strong> ' . $coupons_list . '</p></div>';
    } // endif get_used_coupons ?>

    Now it works perfect!! Just the way I want it to!

  7. hanse111
    Member
    Posted 2 weeks ago #

    Hi Guys,

    i am not quiet sure where to put which part of this plugin!

    I want to show the discount codes on my woocommerce invoices.

    Can anyone explain it to me? thx in advance

Reply

You must log in to post.

About this Plugin

  • WooCommerce Print Invoice & Delivery Note
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.