2017-10-19 54 views

Répondre

0

Vous pouvez facilement ajouter une icône (une image) aux passerelles de paiement dans la page de paiement.

Mais dans Woocommerce cette icône est située après le titre. Pour changer avant le titre vous avez besoin pour modifier le modèle lié checkout/payment-method.php à ligne 27 de ceci:

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

à ceci:

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

et économisez ... S'il vous plaît voir: How to Override WooCommerce Templates via a Theme ...

Vous aurez besoin de télécharger l'ima ge (s) dans un dossier de votre thème comme "assets" par exemple.

Pour chaque passerelle, vous pouvez activer une image personnalisée, ou retourner la valeur par défaut d'un, en utilisant cette fonction personnalisée accroché dans woocommerce_gateway_icon crochet d'action:

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; 
} 

Code va dans le fichier function.php de votre actif thème enfant (ou thème) ou également dans un fichier plugin.

Testé sur WooCommerce 3 et fonctionne.


Comment obtenir la passerelle ID:
Allez sur WC Paramètres> Commander (fin de la page) répertoriés dans la colonne ID passerelle

enter image description here