Hi @fmh999,
I am not sure I understand your question.
I know where the SVG icon is located (obviously) however I cannot seem to find the location of that url in PHP,
Are you asking how to find that url programmatically using PHP?
Kind Regards,
Thread Starter
fmh999
(@fmh999)
I would like to change the icon to a different smaller icon and I am asking which PHP template is that icon located? I want to overwrite that template in my child theme.
WooCommerce handles the html responsible for the rendering of that icon, so it’s a WooCommerce template that you would be looking to overwrite.
woocommerce/templates/checkout/payment-method.php
. You will see a reference to $gateway->get_icon()
.
Or you could use the WooCommerce filter woocommerce_gateway_icon
to change the icon which is what I’d recommend you do since you don’t have to overwrite any templates.
Example:
add_filter('woocommerce_gateway_icon', function($icon, $payment_method){
if($payment_method === 'stripe_applepay'){
$icon = ''; //your icon url
}
return $icon;
}, 10, 2);
Kind Regards,
Thread Starter
fmh999
(@fmh999)
Okay I copied that code into functions.php but its not working.
$icon = ”; //your icon url
The url I’ve inserted above is showing up in the Label rather than actually changing the icon.
@fmh999 I’d recommend you take a look at the WooCommerce source code so you understand why that’s happening. There’s some more work you have to put in to that example. WC expects the icon variable to be an html string.
Here is a snippet from the WC source code:
public function get_icon() {
$icon = $this->icon ? '<img src="' . WC_HTTPS::force_https_url( $this->icon ) . '" alt="' . esc_attr( $this->get_title() ) . '" />' : '';
return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
}
So you want something like:
add_filter('woocommerce_gateway_icon', function($icon, $payment_method){
if($payment_method === 'stripe_applepay'){
$icon_url = 'my-custom-url';
$icon = '<img src="' . WC_HTTPS::force_https_url( $icon_url ) . '" alt="' . esc_attr( $this->get_title() ) . '" />'
}
return $icon;
}, 10, 2);
Thread Starter
fmh999
(@fmh999)
Correction:
I’ve forgot to add <img src="url" />
there and it is now working!
Thank you for your help
-
This reply was modified 2 years, 6 months ago by
fmh999.