• Resolved onevisu

    (@onevisu)


    Hi. I’m looking for a solution how to add used coupon codes to the invoice summary? I’m using standard WooCommerce coupons.

    Is there any quick way to do it?

    Many thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I was having the same problem and managed to write this:

    function example_custom_order_fields( $fields, $order ) {
        $new_fields = array();
    	
    	$coupon_codes = $order->get_coupon_codes();
        
    	$coupons_string = '';
    	
    	foreach($coupon_codes as $coupon){
    		$coupons_string .= $coupon.', ';
    	}
    	
    	$new_fields[0] = array( 
                'label' => 'Coupon Code(s)',
                'value' => $coupons_string
        );
        
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'example_custom_order_fields', 10, 2 );

    I originally wanted to list the coupons (just the names/codes) in the bottom of the invoice below the Subtotal line, like how it lists SKUs under Product names. However, this code just adds the coupon codes to the order info section, below Order Date and Payment Method. This seems like the best method for adding the coupon codes without editing the plugin files directly.

    Let me know if you found a different solution.

    Plugin Support kenil802

    (@kenil802)

    Hi @onevisu,

    We have checked the code shared by @armariussoftware and found that the solution which was shared by @armariussoftware is correct. So, please do check with that code and see whether it works or not.

    Regards,
    Kenil Shah

    Thread Starter onevisu

    (@onevisu)

    @armariussoftware thank you! thank you so much ??

    It’s working great.

    • This reply was modified 4 years, 1 month ago by onevisu.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add Coupon Codes to the Invoice PDF’ is closed to new replies.