skip to Main Content

I am modifying one of the WooCommerce email templates and adding text based on what payment method is used:

if ( 'bacs' == $order->get_payment_method() ){
    echo "We are awaiting payment" ;
    echo $order->get_order_number();
}
elseif ( 'paypal' == $order->get_payment_method() )  {
    echo "Text2";
}
else {
    echo "Text3;
}

I need to add the order ID into the first text (for BACS), so that it would display:

We are awaiting payment. Order reference: 1234 (your order number).

How can I add the order number into my plain text?

2

Answers


  1. you can add string using . notation in php.

    like with "previous string".$order->get_order_number() , you can append order number to preceding string.

    if ( 'bacs' == $order->get_payment_method() ) {
        echo "We are awaiting payment. Order reference: ".$order->get_order_number();
    
    } elseif ( 'paypal' == $order->get_payment_method() ) {
        echo "Text2";
    } else {
        echo "Text3";
    }
    
    Login or Signup to reply.
  2. You can use PHP printf() to incorporate a variable value in a displayed text string as follows:

    if ( 'bacs' === $order->get_payment_method() ) {
        printf( __("We are awaiting payment. Order reference: %s (your order number).", "woocommerce"), $order->get_order_number() );
    } elseif ( 'paypal' === $order->get_payment_method() ) {
        echo __("Text2", "woocommerce");
    } else {
        echo __("Text3", "woocommerce");
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search