How to hook a pay now button to the bottom of WooCommerce Customer Invoice Template?

Viewed 12

I am trying to add a Pay Now button to the bottom of the Customer invoice / Order details email that gets sent manually.

I'm getting a fatal error (Too few arguments to function 1 passed and exactly 2 expected) when running this code:

 //Add Pay Now button to invoice email
 add_action('woocommerce_email_footer', 'rnr_customer_order_invoice_paynow',20,2 );

 function rnr_customer_order_invoice_paynow($order, $email) {   

   if ( $email->id == 'customer_invoice' ) { 
 
   $pay_now_url = esc_url( $order->get_checkout_payment_url() );
 
   echo '<a"href=" ' . $pay_now_url . '">Pay Now</a>';
    
   }

 }
1 Answers

I figured out why I can't hook into the footer. The woocommerce_email_footer hook only has the $email attribute, not the $order attribute. I hooked into woocommerce_email_after_order_table which has 4 attributes available, including $order.

However this does not answer the original question of how to hook into the bottom of the template.) Perhaps with some global variable to get the $order information?

 //Add Pay Now button to invoice email
 add_action('woocommerce_email_after_order_table', rnr_customer_order_invoice',20,4 ); 

 function rnr_customer_order_invoice($order, $sent_to_admin, $plain_text, $email ) 
 {   

   if ( $email->id == 'customer_invoice' ) { 
 
   $pay_now_url = esc_url( $order->get_checkout_payment_url() );
 
   echo '<a"href=" ' . $pay_now_url . '">Pay Now</a>';
    
   }

 }
Related