gpt4 book ai didi

php - 在 Woocommerce 付款方式标题上添加图片

转载 作者:行者123 更新时间:2023-12-01 13:29:20 24 4
gpt4 key购买 nike

在 Woocommerce 中,我计划在银行名称插件 BACS 之前添加图像。现在我已经输入了银行名称和其他设置,并且已经尝试在银行名称之前输入 HTML,但它不起作用。

最佳答案

您可以在结帐页面中轻松地将图标(图像)添加到支付网关。

But in Woocommerce this icon is located after the title. To change it before the title you should need to edit the related template checkout/payment-method.php at line 27 from this:

      <?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?>

to this:

      <?php echo $gateway->get_icon(); ?> <?php echo $gateway->get_title(); ?>

and save … Please see: How to Override WooCommerce Templates via a Theme



例如,您需要将主题中文件夹中的图像作为“ Assets ”上传。

对于每个网关,您可以启用自定义图像,或返回默认图像,使用 Hook 在 中的自定义函数。 woocommerce_gateway_icon Action Hook :
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';

// Setting (or not) a custom icon to the payment IDs
if($gateway_id == 'bacs')
$icon = '<img src="' . WC_HTTPS::force_https_url( "$path/bacs.png" ) . '" alt="' . esc_attr( $title ) . '" />';
elseif( $gateway_id == 'cheque' )
$icon = '<img src="' . WC_HTTPS::force_https_url( "$path/cheque.png" ) . '" alt="' . esc_attr( $title ) . '" />';
elseif( $gateway_id == 'cod' )
$icon = '<img src="' . WC_HTTPS::force_https_url( "$path/cod.png" ) . '" alt="' . esc_attr( $title ) . '" />';
elseif( $gateway_id == 'ppec_paypal' || 'paypal' )
return $icon;

return $icon;
}

代码在您的事件子主题(或主题)的 function.php 文件中或任何插件文件中。

在 WooCommerce 3 上测试并有效。

How to get the gateway ID:
Go on WC Settings > Checkout (end of the page) listed in the Gateway ID column



enter image description here

关于php - 在 Woocommerce 付款方式标题上添加图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46823669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com