2017-10-19 147 views

回答

0

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

但是在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(); ?> 

,并保存...请参阅:How to Override WooCommerce Templates via a Theme ...

您需要将ima例如,ge(s)在主题的文件夹中显示为“资产”。

为每个网关可以启用自定义图像,或返回默认的一个,使用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
去WC设置>结帐(页面结束)在网关ID列

enter image description here

上市