I’m using the following code to add a custom fee based on payment method:
function stackoverflow_apply_payment_gateway_fee() {
$payment_method = WC()->session->get( 'chosen_payment_method' );
if( $payment_method == 'paypal' ) {
$label = 'PayPal Fee <span>HTML</span>';
$cart_subtotal_fee = WC()->cart->get_subtotal();
$amount = 5;
WC()->cart->add_fee( $label, $amount, true, 'standard' );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'stackoverflow_apply_payment_gateway_fee' );
I want to show an icon next to the label using HTML, like this:
$label = 'PayPal Fee <span>HTML</span>';
However string will be (esc_html) escaped for HTML tags. How can I make it work with HTML tags to show my icon?
2
Answers
There is a filter hook called
esc_html
in WP esc_html function that you can use. you can append your icon HTML to your label. check below code. code will go in your active theme functions.php file.Another alternative would be to copy the templates over to your theme (or child theme) from the
woocommerce/templates
directory:In those files wou will find this code where the
esc_html
function is, and edit it as you need: