• Resolved steveconnerton

    (@steveconnerton)


    Looking to show the credit card type (Visa, AMEX etc.) from a given order in the admin new order email notification, but am struggling to get it working. Here is what I came up with. I’m not very good with php, so apologies if this is not even close. This is what I added to my functions.php:

    add_action( ‘woocommerce_email_after_order_table’, ‘add_card_type_to_admin_new_order’, 15, 2 );

    function add_card_type_to_admin_new_order( $order, $is_admin_email ) {
    if ( $is_admin_email ) {
    echo ‘<p>Card Type: ‘ . $order->credit_card_type_label . ‘</p>’;
    }
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thomas Shellberg

    (@shellbeezy)

    Automattic Happiness Engineer

    There is a native WooCommerce function for translating a card brand into text:

    wc_get_credit_card_type_label

    But this is used within the context of viewing saved cards as it requires a token to be created.

    The WC_Payment_Token_CC class has functions for retrieving the card type if a token was used.

    I’m pretty sure this information isn’t stored as part of an order, though, so it would be impossible to grab unless you grabbed it yourself and stored it from the Checkout page.

    Thread Starter steveconnerton

    (@steveconnerton)

    If it helps, I am using the CyberSource Gateway Plugin and the card type does show up on the order page as a note with the last four digits and the card type.

    Thomas Shellberg

    (@shellbeezy)

    Automattic Happiness Engineer

    I had a quick look through their code(if you’re using the plugin developed by SkyVerge) and it has the following:

    $order->payment->card_type = SV_WC_Payment_Gateway_Helper::card_type_from_account_number( $order->payment->account_number );

    Maybe that will help you, although, it might be best to contact the gateway developer as WooCommerce doesn’t look like it can do this itself.

    Thread Starter steveconnerton

    (@steveconnerton)

    Awesome! Thanks for the help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Showing Card type in Admin New Order email’ is closed to new replies.