• Resolved atomonelone

    (@atomonelone)


    Hi!
    I use a plugin to generate a pdf of the current items in cart and I would like to add the configurator data in the pdf but I can’t quite figure out how to get it done.
    Maybe you can help me with this?

    The function I’m using to display information only takes $id and $html and I I’m pretty sure I need to do something like this:

    function show_product_information_pdf ($html, $id) {
    global $woocommerce, $product;
    	if (count(WC()->cart->get_cart()) > 0) {
    		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
    			if (($cart_item['product_id']) && isset( $cart_item['configurator_data'] )) {
    			$htmloutput = '';

    Then I probably need a foreach loop to get the choices?
    I’m kinda stuck and your help would be greatly appreciated!
    If you need me to explain it further please tell me and if possible I would also like to get the generated image to be able to display it.
    Thank you!

    • This topic was modified 2 years, 3 months ago by atomonelone.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Marc Lacroix

    (@marcusig)

    Hi there,

    Yes you’ll then have to do a foreach loop with $cart_item['configurator_data'].
    You’ll get the data by doing something like this:

    foreach ($configurator_data as $item) {
        $layer_name = $item->get_layer( 'name' );
        $choice_name = $item->get_choice( 'name' );
    }

    There are other things you may want to check, but that’s mostly it.
    You can take a look at the cart handling class for other options:

    https://github.com/marcusig/woocommerce-product-customizer/blob/master/src/inc/frontend/cart.php

    You’ll find for example the code which displays the configuration image in the cart:
    https://github.com/marcusig/woocommerce-product-customizer/blob/master/src/inc/frontend/cart.php#L208

    Marc

    Thread Starter atomonelone

    (@atomonelone)

    Hi Marc!
    Thanks for the help and the links.
    I tried doing it like this:

    if (($cart_item["product_id"]) && isset( $cart_item["configurator_data"] )) {
    	$configurator_data = $cart_item["configurator_data"];
    	$htmloutput = "";
    		foreach ($configurator_data as $item) {
        			$layer_name = $item->get_layer( 'name' );
        			$choice_name = $item->get_choice( 'name' );
    			$htmloutput = $layer_name . $choice_name;
    		}
    }
    return $htmloutput

    But It will only return one single choice even though there is 5 different on the product. I tried looking trough the cart code but I can’t quite figure it out. Did I do something wrong?
    I really want to get the conditional logic and use this plugin on our website but it’s vital I can show all the information in the Pdf.
    I’m really greatful for any further assitance.

    Thank you for your time.

    Plugin Contributor Marc Lacroix

    (@marcusig)

    The issue in the code you shared is that you override the htmloutput every time.

    $htmloutput = $layer_name . $choice_name;
    should be

    $htmloutput .= $layer_name . $choice_name;

    note the .=

    Marc

    Thread Starter atomonelone

    (@atomonelone)

    Ahh ofcourse! How did I miss that?!

    Thank you so much for the help! I really appreciate it!

    I’ll mark this as resolved.

    I might have some questions about getting the image but I will try a few stuff out before begging for help haha. Thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show cart item configurator data in Pdf’ is closed to new replies.