将图标添加到自定义WooCommerce付款网关 [英] Add an icon to custom WooCommerce payment gateway

查看:54
本文介绍了将图标添加到自定义WooCommerce付款网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向我的付款网关添加自定义图标.我已经阅读了WOO网关API,并获得了零帮助.这是我的下面的代码.请帮助我找到一种包含图标的实用方法,以便在前端添加一个图标.谢谢

I would like to add a custom icon to my payment gateway. I have read the WOO gateway API and have zero help. This is my code below. please help me find a functional way to include the icon so I have an icon on my front end. Thanks

<?php if ( ! defined( 'ABSPATH' ) ) { exit; }

add_filter( 'woocommerce_payment_gateways', 'init_wpuw_gateway' );
function init_wpuw_gateway ( $methods ) 
{
    $methods[] = 'WC_Gateway_WPUW'; 
    return $methods;
}


if( class_exists('WC_Payment_Gateway') ):
class WC_Gateway_WPUW extends WC_Payment_Gateway {

    /**
     * Constructor for the gateway.
     */
    public function __construct() {

        $plugin_dir = plugin_dir_url(__FILE__);

        $this->id                 = 'wpuw';

        //If you want to show an image next to the gateway’s name on the frontend, enter a URL to an image.
        $this->icon               = apply_filters( 'woocommerce_gateway_icon', ''.$plugin_dir.'/assets/paysecure.png' );
        $this->method_title       = __( 'User Wallet', 'woocommerce' );
        $this->method_description = __( 'Have your customers pay with their user wallet balance.', 'woocommerce' );
        $this->has_fields         = false;

推荐答案

尝试使用反斜杠而不是斜杠,而不用变量 $ plugin_dir

Try with backslash instead of slash without concatenating the initial empty string with the variable $plugin_dir

$this->icon = apply_filters( 'woocommerce_gateway_icon', $plugin_dir.'\assets\paysecure.png' );

这篇关于将图标添加到自定义WooCommerce付款网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆