PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 11, 2022

[FIXED] How can I add the icon corresponding to each payment method that is saved in a WooCommerce user's account?

 November 11, 2022     hook-woocommerce, payment-gateway, payment-method, woocommerce, wordpress     No comments   

Issue

I am looking for the saved payment methods section, to include the icon of each of the cards that users use (Visa, Master card, Amex) how could I add this to WooCommerce?

Current payment method section:

enter image description here

Final idea:

enter image description here


Solution

enter image description here

add_action('woocommerce_account_payment_methods_column_method', 'woocommerce_account_payment_methods_column_data', 10, 1);

function woocommerce_account_payment_methods_column_data($method) {

    if (!empty($method['method']['brand'])) {
        $card = strtolower($method['method']['brand']);
        $card_url = "https://woocommerce.com/wp-content/plugins/woocommerce-payments/assets/images/cards/$card.svg";
    }
    if (!empty($method['method']['last4']) && isset($card_url)) {
        /* translators: 1: credit card type 2: last 4 digits */
        echo '<span><p style="float:left;margin-right:5px;"><img height="40px" width="40px;" src=' . $card_url . ' /></p><p  style="float:left">' . sprintf(esc_html__('%1$s ending in %2$s', 'woocommerce'), esc_html(wc_get_credit_card_type_label($method['method']['brand'])), esc_html($method['method']['last4'])) . "</p></span>";
    } else {
        echo esc_html(wc_get_credit_card_type_label($method['method']['brand']));
    }
}


Answered By - mujuonly
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing