Skip to content
Advertisement

Add an icon to custom WooCommerce payment gateway

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;

Advertisement

Answer

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.'assetspaysecure.png' );
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement