我正在使用WooCommerce的“ WooCommerce PayPal Checkout Gateway”插件,并且希望在结账页面上“付款选项”部分中使用自定义图片。
我尝试了以下方法,但均无济于事;我认为它们可能是针对不使用插件的默认PayPal实施?
add_filter( 'woocommerce_paypal_icon', 'my_replace_paypal_icon', 99 );
function my_replace_paypal_icon() {
return 'https://your_image_url';
}
.. and ...
add_filter( 'woocommerce_gateway_icon', 'my_paypal_gateway_icon', 10, 2 );
function paypal_gateway_icon( $icon, $id ) {
if ( $id === 'paypal' ) {
return '<img src="' . get_bloginfo('stylesheet_directory') . '/images/woocommerce-icons/cards.png" alt="Authorize.net" />';
} else {
return $icon;
}
}
有一种简单的方法吗?
答案 0 :(得分:1)
对于Woocommerce默认的Paypal付款网关,您将仅使用以下内容:
add_filter( 'woocommerce_paypal_icon', 'custom_paypal_icon', 10, 2 );
function custom_paypal_icon( $icon ) {
return '<img src="' . get_bloginfo('stylesheet_directory') . '/images/woocommerce-icons/cards.png" alt="Paypal" />';
}
代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。
对于插件WooCommerce PayPal Checkout Payment Gateway,请尝试以下(正确的付款方式ID为ppec_paypal
):
add_filter( 'woocommerce_gateway_icon', 'custom_payment_gateway_icons', 10, 2 );
function custom_payment_gateway_icons( $icon, $gateway_id ){
// For Paypal Checkout (or Paypal Express) only
if( $gateway_id == 'ppec_paypal' ) {
$icon = '<img src="' . get_bloginfo('stylesheet_directory') . '/images/woocommerce-icons/cards.png" alt="Paypal Express" />';
}
return $icon;
}
代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。