繁体   English   中英

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

[英]Add an image on Woocommerce payment method title

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

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

但在Woocommerce该图标位于标题 要在标题之前更改它,您需要在27编辑相关模板checkout/payment-method.php

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

对此:

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

并保存……请参阅:如何通过主题覆盖 WooCommerce 模板……

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

对于每个网关,您可以启用自定义图像,或返回默认图像,使用挂钩在woocommerce_gateway_icon操作挂钩中的此自定义函数:

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 上测试并有效。


如何获取网关ID
转到网关 ID 列中列出的WC 设置 > 结帐(页面末尾)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM