• Resolved webinetannette

    (@webinetannette)


    Hi everyone, I’m trying to set the used coupon code on the Invoice. I’ve a custom template for the invoices. Whit this code I get the coupon on the invoice, works great:

    add_action( 'wpo_wcpdf_after_order_details', 'wpo_wcpdf_add_coupon_code_and_description', 10, 2 );
    function wpo_wcpdf_add_coupon_code_and_description ($template_type, $order) {
    	if( $coupon_items = $order->get_coupons() ) {
    		foreach ( $coupon_items as $coupon_item ) {
    			$coupon = new WC_Coupon( $coupon_item->get_code() );
    			empty( $coupon->get_description() ) ? printf ( '<p><strong>%s</strong></p>', $coupon->get_code() ) : printf ( '<p><strong>%s:</strong> %s</p>', $coupon->get_code(), $coupon->get_description() );
    		}
    	}
    }

    But; when I want to export invoices in bulk. I get an error:

    Cannot redeclare wpo_wcpdf_add_coupon_code_and_description() (previously declared in /subdomains/…./woocommerce/pdf/mb/invoice.php:175) in /subdomains/…./woocommerce/pdf/mb/invoice.php on line 175

    Can someone help me adjust the code?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @webinetannette

    Where do you have that code? Because it seems that you have it running twice. You must remove it from here: /subdomains/…./woocommerce/pdf/mb/invoice.php:175

    Thread Starter webinetannette

    (@webinetannette)

    I’ve it only once in the template.. that is the weird thing. And when I get the pdf invoice in an order it works fine. But when I want to get it in bulk, woommerce -> orders -> bulk actions -> select a couple orders -> pdf invoice ; than I get that error.

    Plugin Contributor alexmigf

    (@alexmigf)

    Cannot redeclare means that you are running the same function twice. Why are you having the function in the template? It should be in the functions.php file of your WP theme.

    Thread Starter webinetannette

    (@webinetannette)

    Ah ofcourse , stupid of me. Works now perfect. Thank you.

    Plugin Contributor alexmigf

    (@alexmigf)

    Glad to hear that ??

    Have a nice day!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Coupon description (title) on invoice’ is closed to new replies.