Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce remove bank account number on order thank you page

I am using woocommerce site and I have enabled the direct bank transfer payment method. I want to remove the account number of order thank you page but want to show in emails. Same function is called in both cases.

How can I differentiate it to show the account number only in email.. not on thank you page. I have tried it like:

global $pagename;
if($pagename == "checkout"){
//remove bank account number
}else{
//show bank account number
}

But its Not working.. can anyone give me suggestions...

Also i used this.

add_action('woocommerce_before_template_part', 'thankyou_bacs');

function thankyou_bacs() {
    /* get bacs payment gateway class */
    $methods = WC()->payment_gateways->payment_gateways();
    $bacs_class = $methods['bacs'];
    unset($bacs_class->account_details[0]['account_name']);
    unset($bacs_class->account_details[0]['account_number']);
}

working great for checkout page, but hiding these details from email too. :( :(

like image 491
Maha Dev Avatar asked Jun 04 '16 05:06

Maha Dev


People also ask

How do I customize a thank you page in WooCommerce?

There are a few different ways you can customize your thank you page. Manual methods include coding a custom page template, using WooCommerce hooks via your theme’s functions.php file, and adding custom styles to your child theme’s stylesheet. If you’re not comfortable with coding, you can use a plugin that lets you customize your thank you page.

How to remove the bank details from the wpautop output?

Here is the complete code for removing the bank details: echo wpautop ( wptexturize ( $gateway- > instructions ) ) . PHP_EOL; 1. We need to remove the hook already in place to output the bank details: line 21 – 30.

How do you say thank you for receiving an order?

The default text is, “Thank you. Your order has been received.” The example below adds just 1 sentence, “A receipt has been sent to you via email.” You can replace that with your own text below. $new = $text .


1 Answers

You could try to use conditional is_page('checkout') or is_checkout(), first.

Then you can use remove_action() for removing your hooked function from checkout page only…

This way you don't have to edit templates.

---- Update ----

USING CSS:
You can also use CSS to hide just account number targeting one of this selectors/classes. For example, in one of my e-commerce, this are the css selectors to target:

  • .woocommerce-checkout ul.order_details.bacs_details
  • .woocommerce-checkout ul.order_details.bacs_details > li.iban
  • .woocommerce-checkout ul.order_details.bacs_details > li.bic

With: display:none;

---- update2 ----

Using your hook with a conditional:

1). Inside:

add_action('woocommerce_before_template_part', 'thankyou_bacs');
function thankyou_bacs() {
    if(is_checkout()){
        /* get bacs payment gateway class */
        $methods = WC()->payment_gateways->payment_gateways();
        $bacs_class = $methods['bacs'];
        unset($bacs_class->account_details[0]['account_name']);
        unset($bacs_class->account_details[0]['account_number']);
    }
}

2). Outside:

if(is_checkout()){
    add_action('woocommerce_before_template_part', 'thankyou_bacs');
    function thankyou_bacs() {
        /* get bacs payment gateway class */
        $methods = WC()->payment_gateways->payment_gateways();
        $bacs_class = $methods['bacs'];
        unset($bacs_class->account_details[0]['account_name']);
        unset($bacs_class->account_details[0]['account_number']);
    }
}
like image 109
LoicTheAztec Avatar answered Sep 18 '22 16:09

LoicTheAztec