• Resolved mitke1990

    (@mitke1990)


    Hi,

    Is it possible to add Checkout Field Manager field to PDF file. I tried to add in wc-cart-pdf/templates/cart-table.php, for example:

            <?php echo esc_html( $customer->get_billing_first_name() . ' ' . $customer->get_billing_last_name() ); ?><br>
            <?php echo esc_html( $customer->get_billing_email() ); ?><br>
            <?php echo esc_html( $customer->get_billing_phone() ); ?><br>
            <?php echo esc_html( $customer->get_billing_city() ); ?><br>
            <?php echo esc_html( $customer->get_billing_wooccm14() ); ?>

    Last line is for Checkout Field Manager conditional field, but it does not appear in the pdf file. Can you help me?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author David Jensen

    (@dkjensen)

    Hello

    It was unclear to me if you were editing the plugin file directly, but if so you should not do that as if you update the plugin it will override your changes. You can keep your modifications free from conflicting with updates by copying the PDF template from the plugin folder?wc-cart-pdf/templates/cart-table.php?into your child theme folder?child-theme/woocommerce/wc-cart-pdf/cart-table.php.

    Then inside your child theme, edit that cart-table.php file.

    Secondly, looking at the code of the WooCommerce Checkout Field Manager plugin, I do not see any method called get_billing_wooccm14().

    What field are you trying to pull in and where is it defined? If this is a custom field on checkout, it will have to be saved to the customers profile BEFORE they are downloading the PDF, otherwise there is not a way for the PDF to know the value.

    Thread Starter mitke1990

    (@mitke1990)

    Thank you for your prompt response.

    Yes, I use child.

    For each default field in the checkout, everything appears in the PDF file, but for any custom field created with the plugin Checkout Field Manager, it does not appear in pdf file… Can you help me to add this in pdf file?

    Plugin Author David Jensen

    (@dkjensen)

    I see. So I assume you are using the capture customer information on checkout option of the WC Cart PDF plugin. So what you will do is the following:

    The WC Cart PDF plugin wont capture your custom fields out of the box, so in order to tell it to capture it, add the following to your child theme functions.php file or in a custom plugin somewhere:

    add_filter( 'wc_cart_pdf_capture_customer_fields', function( $capture_fields ) {
    	$capture_fields[] = 'billing_wooccm14'; // Custom field name.
    
    	return $capture_fields;
    
    } );

    You can find the value of billing_wooccm14 using your browsers inspect / developer tools:

    https://i.imgur.com/AOdUF1L.png

    Then inside the cart-table.php file within your child theme, add the following where you would like this value displayed:

    <?php printf( '%s: %s', esc_html__( 'My Custom Field' ), esc_html( WC()->checkout->get_value( 'billing_wooccm14' ) ) ); ?>

    Again, replacing billing_wooccm14 with your custom field name.

    Hope this helps

    Thread Starter mitke1990

    (@mitke1990)

    I did everything as you said but it doesn’t work. This is PDF file screenshot:

    https://generalprinting.tilda.in.rs/wp-content/uploads/2023/12/custom-field.png

    And this is the link to Checkout:

    https://generalprinting.tilda.in.rs/checkout/

    And thank you very much for everything!

    Plugin Author David Jensen

    (@dkjensen)

    In my example I used: billing_wooccm14

    Can you confirm this is the name of the field on your checkout?

    Also, these values are stored as a cookie in the browser, but only when you type something in the field, or change the field. Can you try triggering this by changing the value of your custom field and then try the PDF again?

    Thread Starter mitke1990

    (@mitke1990)

    And in my case it is billing_wooccm14

    https://generalprinting.tilda.in.rs/wp-content/uploads/2023/12/custom-field2.png

    I tried this olso:

    <?php echo esc_html( $customer->get_billing_first_name() . ' ' . $customer->get_billing_last_name() ); ?><br>
    <?php echo esc_html( $customer->get_billing_email() ); ?><br>
    <?php echo esc_html( $customer->get_billing_phone() ); ?><br>
    <?php echo esc_html( $customer->get_billing_city() ); ?><br>
    <?php printf( '%s: %s', esc_html__( 'My Custom Field' ), esc_html( WC()->checkout->get_value( 'billing_wooccm14' ) ) ); ?>
    <?php printf( '%s: %s', esc_html__( 'My Custom Field2' ), esc_html( WC()->checkout->get_value( 'billing_wooccm13' ) ) ); ?>

    in cart-table.php

    add_filter( 'wc_cart_pdf_capture_customer_fields', function( $capture_fields ) {
    	$capture_fields[] = 'billing_wooccm14'; // Custom field name.
    	$capture_fields[] = 'billing_wooccm13'; // Custom field name2.
    
    	return $capture_fields;
    
    } );

    in functions.php

    I hope I haven’t made a mistake since I’m a beginner

    Plugin Author David Jensen

    (@dkjensen)

    Can you ensure the “Capture customer information on checkout” is enabled under Appearance > Customize > WooCommerce > Cart PDF?

    Plugin Author David Jensen

    (@dkjensen)

    Can you ensure the “Capture customer information on checkout” is enabled under Appearance > Customize > WooCommerce > Cart PDF?

    Thread Starter mitke1990

    (@mitke1990)


    Oh man ?? I forgot about that! Everything works prefect now! Thanks again!

    Plugin Author David Jensen

    (@dkjensen)

    Awesome glad we could get that sorted!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘PDF file with Checkout Field Manager’ is closed to new replies.