Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Filtering a Woocommerce Function WordPress

  • SOLVED

On the Woocommerce cart and checkout pages, there is a function which displays all of the meta associated with a product in the cart. The function whole function that displays the meta is

echo $woocommerce->cart->get_item_data( $values );

I need to somehow filter the get_item_data function to not load certain meta values.

I am not looking for something to simply hide or not display the meta, I want it to be filtered and never loaded inside a function. I am not sure if this is possible or not, but wanted to check to see if anyone had any ideas.

You can see an example of the cart meta by going to https://hookahi.com/guides/hucks-charters/ and adding a trip to your cart from the ones listed on that page.

The function can be found inside the woocommerce plugin in the classes directory in the file called classes-wc-cart.php (woocommerce/classes/classes-wc.cart.php) on line 1959 if that helps too. And of course you can download a copy of Woocommerce quickly right here: http://wordpress.org/extend/plugins/woocommerce/

Please note I am in the northeast US and currently do not have power so my responses may be slow

Answers (2)

2012-11-04

Francisco Javier Carazo Gil answers:

Hi,

You should create a function into your functions.php, that will be based on WooCommerce API and that should be the same than get_item_data (line 477 of woocommerce/classes/classes-wc.cart.php) and then in this new function make the filter.

How? For example, in the loop foreach, include a condition that should say: if(I don't want this data) continue to avoid this data.


Kyle comments:

Yes, I believe this is what I am looking for, but I do not know how to do it. I am not a good enough php coder to make that function.


Francisco Javier Carazo Gil comments:

Ok, perfect, send me via PM FTP details to do it and also please tell me which data and which not, you want to include.

2012-11-04

Arnav Joy answers:

i do not know if it will work or not , but can you write following function to functions.php and provide me output

add_filter( 'woocommerce_get_item_data', 'modified_get_item_data' ,10,2 );

function modified_get_item_data(array(), $cart_item){

print_r($cart_item);

}


Kyle comments:

Hello thanks for the reply, but this crashed site