Hi @kminderhout,
The PayPal function located in wc-braintree.js does not have an onClick function.
What are you trying to do with this customization?
Within the PayPal.prototype.render_options function there is an onClick function. If that’s the one you’re referring to then you could do the following:
1. Create your own custom script that is enqueued in the header of your WordPress site. 2. Make one of its dependencies the wc-briantree.js file.
3. Import wc-braintree.js using a local function and redefine the render_options function.
Here is an example to get you started:
(function(wc_braintree){
// save a reference to the prototype.render_options
var render_options = PayPal.prototype.render_options;
// redefine the render_options function with your custom code
wc_braintree.PayPal.prototype.render_options = function(){
var options = render_options.apply(this, arguments);
var onClick = options.onClick;
options.onClick = function(data, actions){
// your custom code here
// call the original onClick function
onClick.apply(this, arguments);
}.bind(this)
}
})(window.wc_braintree)
-
This reply was modified 5 years, 11 months ago by
Clayton R.
Thanks for suggestion and the snippet! I was wanting to trigger an event that I can use to send a GA Enhanced E-commerce hit.
Am I correct that moving the script to the header wouldn’t be very performative as it would then become a blocking script?
@kminderhout It’s not a lot of Javascript, so it’s not going to cause a noticeable performance hit.
You can put it in the footer if you like, just make sure you make your custom script a dependency for the PayPal script.
True. Thanks again for the help. I’m starting to understand it all, so I’ll give that a try with the dependency.