根据Woocommerce选择的付款方式,在结帐时更改带图像的“付款”按钮

时间:2020-02-13 01:57:58

标签: php wordpress woocommerce payment-gateway hook-woocommerce

通过此功能,我可以更改“付款”按钮上的文字。 我想插入一个小图像。

./src/assets/tshirt/gitF/tshirt.glb 1:4
Module parse failed: Unexpected character '' (1:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

与前端一样,按钮文本将通过使用jQuery的.text()函数进行更改,在此处无法添加类似img标签的html。

我建议您将javascript与jQuery结合使用。应该是这样的:

$( document.body ).on( 'payment_method_selected', function(){
    var selectedPaymentMethod = $( '.woocommerce-checkout input[name="payment_method"]:checked' ).attr( 'id' );
    $( '#place_order' ).find('.payment-icon');
    $( '#place_order' ).prepend('<span class="payment-icon '+ selectedPaymentMethod +'"></span>'); // or any element like from font-awesome.
});
$( document.body ).trigger( 'payment_method_selected' ); // this will trigger on page load, act as initialize the icon.

上面的脚本将添加一个span标签,该标签带有类payment-icon和所选付款方式的ID。然后,您可以使用CSS在此范围内将图标添加为背景。