在结帐时更改WooCommerce

在结帐时更改WooCommerce

本文介绍了在结帐时更改WooCommerce Stripe的付款卡图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在WooCommerce结帐中以不同的方式对Stripe显示的支付卡图标进行排序.

I would like to sort the Stripe displayed payment card icons in a different way in WooCommerce checkout.

WooCommerce Stripe插件支持不提供自定义代码支持,因此他们只是给了我一个代码片段,可以根据我的需要进行修改.此代码段更改了Visa付款图标:

WooCommerce Stripe plugin support does not provide custom code support so they just gave me a code snippet to modify according to my needs. This code snippet changes out the Visa payment icon:

add_filter( 'wc_stripe_payment_icons', 'change_my_icons' );
function change_my_icons( $icons ) {
        // var_dump( $icons ); to show all possible icons to change.
    $icons['visa'] = '<img src="https://shipyouridea.com/wp-content/plugins/woocommerce/assets/images/icons/credit-cards/visa.svg" />';
    return $icons;
}

有人可以修改此代码段,以将支付卡图标顺序更改为 Visa>万事达卡>美国运通>发现>杰西博大来俱乐部?

Could someone please modify this code snippet to change the payment card icon order to Visa > Mastercard > Amex > Discover > JCB > Diners Club?

我还想完全删除JCB和Diners Club付款图标.我目前正在使用一些自定义CSS来隐藏这些图标,但想知道是否有更好的方法.

I would also like to completely remove the JCB and Diners Club payment icons. I'm currently using some custom CSS to hide these icons but was wondering if there's a better way.

推荐答案

您没有使用正确的钩子.另外,显示的图标使用 float:right ,因此它们被反转了.您还可以轻松删除任何图标.

You are not using the right hook. Also the displayed icons use float:right, so they are inverted. You can also remove any icon easily.

以下内容将显示排序的图标为 Visa > Mastercard > Amex >发现:

The following will display sorted icons as Visa > Mastercard > Amex > Discover:

add_filter( 'woocommerce_gateway_icon', 'sort_stripe_payment_icons', 10, 2 );
function sort_stripe_payment_icons( $icons_str, $payment_id ) {
    if ( $payment_id === 'stripe' && is_checkout() ) {
        $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
        $stripe = $available_gateways['stripe'];

        $icons = $stripe->payment_icons();

        $icons_str = '';

        if ( 'USD' === get_woocommerce_currency() ) {
            $icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : '';
            // $icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : '';
            // $icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : '';
        }

        $icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : '';
        $icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : '';
        $icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : '';

    }
    return $icons_str;
}

代码进入活动子主题(或活动主题)的functions.php文件中.经过测试,可以正常工作.

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

这篇关于在结帐时更改WooCommerce Stripe的付款卡图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:17