7

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. :( :(

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Maha Dev
  • 3,915
  • 2
  • 31
  • 50

3 Answers3

6

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']);
    }
}
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Both checkout page and email template using same function of payment gateway. should i use `is_page('checkout')` and `is_checkout()` to differentiate both in payment gateway file?? – Maha Dev Jun 04 '16 at 06:40
  • @MahaDev Both are the same. You can use them instead of `$pagename == "checkout"`… i have updated my question – LoicTheAztec Jun 04 '16 at 06:42
  • I dont want to hide whole the bank details, but just the account number. All other info will be shown to user. `remove_action` will hide it properly, i think. – Maha Dev Jun 04 '16 at 06:44
  • Wouldn't this hide it from email too? becuase whatever i am doing on checkout page, same happens in email. – Maha Dev Jun 04 '16 at 07:09
  • Updated my question. trying another method but facing problems inside that too – Maha Dev Jun 04 '16 at 07:10
1

Look in your Woocommerce plugin folder for the default templates:

\wp-content\plugins\woocommerce\templates\

Then create a new folder called 'woocommerce' under your Wordpress theme:

\wp-content\themes\(your theme name)\woocommerce\

Keeping the same folder structure as under templates, copy all the files/folders across or just the ones you wish to modify. You can now edit the copy under your theme, these should be automatically detected by the plugin as overwritten now. Check under Woocommerce > System Status to ensure it's working.

For the thank you page, it would be under:

\woocommerce\checkout\thankyou.php

Just remove the payment method display from there.

The emails have their own folder too, modify if desired.

For more details: https://docs.woothemes.com/document/template-structure/

3Lancer
  • 88
  • 1
  • 9
0

Via Customise, Additional CSS add:

.woocommerce-bacs-bank-details {
    display: none;
}

If you do this with a live Checkout Page in Customizer you can see the effect.

TobyU
  • 3,718
  • 2
  • 21
  • 32