将图标添加到自定义 WooCommerce 支付网关
Add an icon to custom WooCommerce payment gateway
我想为我的支付网关添加自定义图标。我已阅读 WOO 网关 API 并获得零帮助。这是我下面的代码。请帮助我找到一种包含图标的功能方法,以便我的前端有一个图标。谢谢
<?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
$this->icon = apply_filters( 'woocommerce_gateway_icon', $plugin_dir.'\assets\paysecure.png' );
使用 WooCommerce 过滤器 woocommerce_gateway_icon
您可以通过以下方式将图标添加到支付网关:
/**
* Add Custom Icon
*/
function custom_gateway_icon( $icon, $id ) {
if ( $id === 'custom' ) {
return '<img src="' . plugins_url( 'img/custom.png', __FILE__ ) . '" > ';
} else {
return $icon;
}
}
add_filter( 'woocommerce_gateway_icon', 'custom_gateway_icon', 10, 2 );
试试这个:
$this->icon = trailingslashit( WP_PLUGIN_URL ) . plugin_basename( dirname( __FILE__ ) ) . '/assets/paysecure.png';
我会建议 woocommerce_available_payment_gateways
过滤器。
/**
Add Custom Icon For Cash On Delivery
**/
function cod_gateway_icon( $gateways ) {
if ( isset( $gateways['cod'] ) ) {
$gateways['cod']->icon = get_stylesheet_directory_uri() . '/images/cod.png';
}
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'cod_gateway_icon' );
我想为我的支付网关添加自定义图标。我已阅读 WOO 网关 API 并获得零帮助。这是我下面的代码。请帮助我找到一种包含图标的功能方法,以便我的前端有一个图标。谢谢
<?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
$this->icon = apply_filters( 'woocommerce_gateway_icon', $plugin_dir.'\assets\paysecure.png' );
使用 WooCommerce 过滤器 woocommerce_gateway_icon
您可以通过以下方式将图标添加到支付网关:
/**
* Add Custom Icon
*/
function custom_gateway_icon( $icon, $id ) {
if ( $id === 'custom' ) {
return '<img src="' . plugins_url( 'img/custom.png', __FILE__ ) . '" > ';
} else {
return $icon;
}
}
add_filter( 'woocommerce_gateway_icon', 'custom_gateway_icon', 10, 2 );
试试这个:
$this->icon = trailingslashit( WP_PLUGIN_URL ) . plugin_basename( dirname( __FILE__ ) ) . '/assets/paysecure.png';
我会建议 woocommerce_available_payment_gateways
过滤器。
/**
Add Custom Icon For Cash On Delivery
**/
function cod_gateway_icon( $gateways ) {
if ( isset( $gateways['cod'] ) ) {
$gateways['cod']->icon = get_stylesheet_directory_uri() . '/images/cod.png';
}
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'cod_gateway_icon' );