Closed james-allan closed 3 months ago
@mattallan I'd be curious to know what your thoughts are on this approach. All the cart related functions which hook onto the woocommerce_order_button_text
filter are unaccessible because all our instances of those classes (which aren't static) aren't stored and retrievable anywhere.
This PR adds a method to make them accessible so we can call functions on those instances now. I don't really have any concerns about that. We could add static get_instance()
versions instead. Those classes not being accessible is a bit of pain anyway.
An alternative would be to just trigger the woocommerce_order_button_text
filter and inject into the JS whatever is returned, however, that would mean anyone else hooking onto it would also be affected by that and in that case I think I'd prefer WooCommerce Core just honoured the woocommerce_order_button_text
themselves.
We could add static get_instance() versions instead. Those classes not being accessible is a bit of pain anyway
After discussions with @mattallan we're going to go with this approach as it's cleaner and easier to understand.
After discussions with @mattallan we're going to go with this approach as it's cleaner and easier to understand
So I ended up running into issues with that approach. Namely adding a get_instance()
function to the WCS_Cart_Renewal
class like this
class WCS_Cart_Renewal {
/**
* The single instance of the class.
*
* @var WCS_Cart_Renewal
*/
protected static $instance = null;
/**
* Main WCS_Cart_Renewal Instance.
*
* Ensures only one instance of WCS_Cart_Renewal is loaded or can be loaded.
*
* @return WCS_Cart_Renewal - Main instance.
*/
public static function get_instance() {
if ( is_null( static::$instance ) ) {
static::$instance = new static();
}
return static::$instance;
}
Would mean that all child classes inherit that static variable and I'd need to define an $instance
variable in each child class and that's not great.
I'm going to improve the current approach to incorporate some of Matt's other feedback. Namely the eye sore that is $this->cart_handlers['renewal']
.
@mattallan I've updated this and the accompanying PR over on Woo Subscriptions inline with the changes we spoke about.
Fixes #https://github.com/woocommerce/woocommerce-subscriptions/issues/4628
Description
When you renew, switch or purchase a new subscription the place order button text on the checkout it changed to give the customer more context.
These overrides don't currently apply to the block checkout. This PR fixes that.
How to test this PR
npm run build
as this PR has changes to built JS files.