-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Description
Prerequisites
- I have carried out troubleshooting steps and I believe I have found a bug.
- I have searched for similar bugs in both open and closed issues and cannot find a duplicate.
Describe the bug
The woocommerce_cart_item_name filter in the 7.8.0 cart.php template is applied twice. That leads to issues with plugins that use the filter to adjust the cart item name (as the additional info may be added twice).
Expected behavior
Do only apply the filter once or pass the original, non-filtered $_product->get_name() as first parameter to the next filter call instead of $product_name (which already has been filtered).
Actual behavior
The filter is being applied twice. First on creating the variable:
$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
and during output:
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $product_name, $cart_item, $cart_item_key ) . ' ' );
Steps to reproduce
- Add a snippet to your functions.php:
add_filter( 'woocommerce_cart_item_name', function( $cart_item_name ) {
return $cart_item_name . ' - test';
} );- Add a product to cart
- See how the
-testsuffix is added twice.
WordPress Environment
Latest WP and Woo version. Latest storefront theme.
Isolating the problem
- I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
- This bug happens with a default WordPress theme active, or Storefront.
- I can reproduce this bug consistently using the steps above.