• Resolved summitwinterguard

    (@summitwinterguard)


    I am using the following snippet

    //Add used coupons to PDFs
    add_action( ‘wpo_wcpdf_after_order_details’, ‘wpo_wcpdf_coupons_used’, 10, 2 );
    function wpo_wcpdf_coupons_used ($template_type, $order) {
    if( $used_coupons = $order->get_used_coupons() ) {
    $coupons_list = implode(‘, ‘, $used_coupons);
    echo ‘<h4>’ . __(‘Coupons used’) . ‘</h4>’;
    echo ‘<p>’ . $coupons_list . ‘</p>’;
    }
    }

    This applied the coupon code to the invoice (which works great). Is there a way to get it to add the coupon description instead of or in addition to the coupon code?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor kluver

    (@kluver)

    Hi @summitwinterguard,

    You can use the following code snippet:

    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() );
    		}
    	}
    }
    Thread Starter summitwinterguard

    (@summitwinterguard)

    Thank you so much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add coupon description’ is closed to new replies.