-
Notifications
You must be signed in to change notification settings - Fork 219
Calculate cart totals after running extensions #7490
Conversation
The release ZIP for this PR is accessible via:
|
Size Change: -121 B (0%) Total Size: 992 kB
ℹ️ View Unchanged
|
This works great with Gift Cards! 👌 |
17f1727
to
8889854
Compare
add_action( | ||
'woocommerce_cart_calculate_fees', | ||
function() { | ||
wc()->cart->add_fee( 'Surcharge', 10, true, 'standard' ); | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using fees here because they're the only core cart method that doesn't trigger its own recalc, however, they only work if you add them within this action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works perfect 👌🏼 thanks Nadir.
The tests you've added are great too. Something to work on in future could be: based on pca54o-4Bi-p2#comment-4596 we should try adding a test where two "extensions" use the same extensibility point and ensure they both get the expected results.
* calculate cart totals afer running extensions * update totlas call in CartUpdateCustomer * test that cart is recalcing
* Empty commit for release pull request * Calculate cart totals after running extensions (#7490) * calculate cart totals afer running extensions * update totlas call in CartUpdateCustomer * test that cart is recalcing * Update changelog in readme * Add release testing notes * Update release date in readme * Bumping version strings to new version. * update readme * Update styles of the Filter by Attribute dropdown so it looks good in TT3 (#7506) * Use theme's body background color as the mini cart contents default background color (#7510) Co-authored-by: Albert Juhé Lluveras <[email protected]> * Price Slider: use `currentColor` for the slider (#7527) * Fixed Price Slider Issue Located where the price slider was hard coded and replaced it. * fix CSS lint * use currentColor instead of hard-coded color for the slider of the Filter By Price block #7130 use currentColor instead of hard-coded color for the slider of the Filte By Price block * use currentColor instead of hard-coded color for the slider of the Filter By Price block #7130 use currentColor instead of hard-coded color for the slider of the Filte By Price block * remove background-color Co-authored-by: EmptySet-Exe <[email protected]> Co-authored-by: Niels Lange <[email protected]> * Make price slider 'inactive' range half transparent so it looks better in dark themes (#7525) * Fix inconsistent button styling with TT3 (#7516) * fix inconsistent button styling with TT3 * use wc_wp_theme_get_element_class_name * add check to be sure that wc_wp_theme_get_element_class_name function exists * Fix Mini Cart Block global styles #7379 (#7515) * Fix Mini Cart Block global styles #7379 Fix Mini Cart Block global styles * add font_size * upload a new build * Bumping version strings to new version. Co-authored-by: github-actions <[email protected]> Co-authored-by: Seghir Nadir <[email protected]> Co-authored-by: Thomas Roberts <[email protected]> Co-authored-by: Luigi <[email protected]> Co-authored-by: Albert Juhé Lluveras <[email protected]> Co-authored-by: Tung Du <[email protected]> Co-authored-by: EmptySet-Exe <[email protected]> Co-authored-by: Niels Lange <[email protected]>
* calculate cart totals afer running extensions * update totlas call in CartUpdateCustomer * test that cart is recalcing
* Empty commit for release pull request * Calculate cart totals after running extensions (woocommerce#7490) * calculate cart totals afer running extensions * update totlas call in CartUpdateCustomer * test that cart is recalcing * Update changelog in readme * Add release testing notes * Update release date in readme * Bumping version strings to new version. * update readme * Update styles of the Filter by Attribute dropdown so it looks good in TT3 (woocommerce#7506) * Use theme's body background color as the mini cart contents default background color (woocommerce#7510) Co-authored-by: Albert Juhé Lluveras <[email protected]> * Price Slider: use `currentColor` for the slider (woocommerce#7527) * Fixed Price Slider Issue Located where the price slider was hard coded and replaced it. * fix CSS lint * use currentColor instead of hard-coded color for the slider of the Filter By Price block woocommerce#7130 use currentColor instead of hard-coded color for the slider of the Filte By Price block * use currentColor instead of hard-coded color for the slider of the Filter By Price block woocommerce#7130 use currentColor instead of hard-coded color for the slider of the Filte By Price block * remove background-color Co-authored-by: EmptySet-Exe <[email protected]> Co-authored-by: Niels Lange <[email protected]> * Make price slider 'inactive' range half transparent so it looks better in dark themes (woocommerce#7525) * Fix inconsistent button styling with TT3 (woocommerce#7516) * fix inconsistent button styling with TT3 * use wc_wp_theme_get_element_class_name * add check to be sure that wc_wp_theme_get_element_class_name function exists * Fix Mini Cart Block global styles woocommerce#7379 (woocommerce#7515) * Fix Mini Cart Block global styles woocommerce#7379 Fix Mini Cart Block global styles * add font_size * upload a new build * Bumping version strings to new version. Co-authored-by: github-actions <[email protected]> Co-authored-by: Seghir Nadir <[email protected]> Co-authored-by: Thomas Roberts <[email protected]> Co-authored-by: Luigi <[email protected]> Co-authored-by: Albert Juhé Lluveras <[email protected]> Co-authored-by: Tung Du <[email protected]> Co-authored-by: EmptySet-Exe <[email protected]> Co-authored-by: Niels Lange <[email protected]>
In a recent refactor #7361 we switched from calling the
cart
endpoint in CartExtensions to calling the schema, which is more efficient and inline with architecture. However, previously when we called the endpoint directly, we were recalculating the cart each time, that refactor removed that.Now, whether we should recalculate totals or not within
CartExtensions
or leave it to extensions is debatable, but we sort of created a regression in which plugins which assumed totals will be recalculated no longer had that.In this PR I ensure we recalculate totals, and refactor some code so the recalculation code is shared.
Testing
XXXX-XXX-XXX-XXX
and 3) updated cart totals that include the gift card discount.WooCommerce Visibility
Changelog