Show cart item data
-
Hi Saravana!
First of all, amazing plugin!
I was hoping you could help me resolve an issue.
I’m using a plugin to generate a pdf(it’s using mPdf as its engine) of all the items added in the woocommerce cart and I need to display the value of my editable WCFF textfield inside the pdf.
I’ve been going down a deep rabbit hole trying to figure out how to do this as I first thought the data was stored as post meta when infact it’s stored as cart item data/session data if I’m not wrong? My knowledge about php is very limited so it’s all about trial and error but I just can’t figure this out.I found a snippet on your website that I tried to use inside my function, but I just get the result “array” back. Also I’m pretty sure using it this way I’m actually outputing the entire cart not just the value of the WCFF field in the cart.
So could you please help me or point me in the right direction to just output the value of the field? It has to be just the value not an array and it has to be pulled from the session data/cart item data since you are able to edit the field in the cart.
I will be forever greatful if you can help me with this! <3
Thank you in advance.Below you can see my function and maybe figure out what I’m trying to do.
add_filter( 'woocommerce_pdf_catalog_before_product_information', 'show_text_pdf', 10, 2); function show_text_pdf ($html, $id) { if( count( WC()->cart->get_cart() ) > 0 ) { foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { if( isset( $cart_item[ "wccaf_fritextutskrift" ] ) ) { echo $cart_item[ "wccaf_fritextutskrift" ]; } } } $html = 'Position: ' . $cart_item; return $html; }
- The topic ‘Show cart item data’ is closed to new replies.