2017-10-19 153 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

上市