Skip to content

Instantly share code, notes, and snippets.

@h2kyaw
Created March 2, 2021 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h2kyaw/a43aec1c1fad5a6adb4178953f9c0148 to your computer and use it in GitHub Desktop.
Save h2kyaw/a43aec1c1fad5a6adb4178953f9c0148 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment