## plugins – apply_filters(woocommerce_get_item_data, …) Causing errors when adding to cart

Question

The /wp-content/plugins/woocommerce/includes/wc-template-functions.php file has a function called wc_get_formatted_cart_item_data() that runs whenever I attempt to add a product to cart. Within that function there’s this block of code

$item_data = apply_filters( 'woocommerce_get_item_data',$item_data, $cart_item ); // Format item data ready to display. foreach ($item_data as $key =>$data ) {
...
}
...
if ( count( $item_data ) > 0 ) { ... }  The apply_filters( 'woocommerce_get_item_data',$item_data, $cart_item ) on the first line returns an empty string which throws a warning when the loop on the $item_data variable runs and a fatal error when count($item_data) runs. Any idea how to fix this issue long-term? currently, I’m just skipping the count() function if $item_data is a string but I want something for solid.

Thank you.

0
4 weeks 2022-07-23T05:17:55-05:00 0 Answers 0 views 0