Skip to content

Instantly share code, notes, and snippets.

@h2kyaw
Created March 2, 2021 15:52
Show Gist options
  • Select an option

  • Save h2kyaw/a43aec1c1fad5a6adb4178953f9c0148 to your computer and use it in GitHub Desktop.

Select an option

Save h2kyaw/a43aec1c1fad5a6adb4178953f9c0148 to your computer and use it in GitHub Desktop.

Revisions

  1. h2kyaw created this gist Mar 2, 2021.
    21 changes: 21 additions & 0 deletions woocommerce_gateway_icon
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    add_filter( 'woocommerce_gateway_icon', 'custom_payment_gateway_icons', 10, 2 );
    function custom_payment_gateway_icons( $icon, $gateway_id ){
    foreach( WC()->payment_gateways->get_available_payment_gateways() as $gateway )
    if( $gateway->id == $gateway_id ){
    $title = $gateway->get_title();
    break;
    }
    // The path (subfolder name(s) in the active theme)
    $path = get_stylesheet_directory_uri(). '/assets/images/payment';
    // Setting (or not) a custom icon to the payment IDs
    if($gateway_id == 'bacs')
    $icon = '<img src="' . WC_HTTPS::force_https_url( "$path/direct-bank.png" ) . '" alt="' . esc_attr( $title ) . '" />';
    elseif( $gateway_id == 'cheque' )
    $icon = '<img src="' . WC_HTTPS::force_https_url( "$path/bank-check.png" ) . '" alt="' . esc_attr( $title ) . '" />';
    elseif( $gateway_id == 'cod' )
    $icon = '<img src="' . WC_HTTPS::force_https_url( "$path/cash-on-delivery.png" ) . '" alt="' . esc_attr( $title ) . '" />';
    elseif( $gateway_id == 'ppec_paypal' || 'paypal' )
    return $icon;

    return $icon;
    }