• Resolved shocksalmighty

    (@shocksalmighty)


    Hi, I’m using some custom fields that only display if you are purchasing a certain product and have used the code provided from your support docs at the link below which works fine however it displays the H3 text on all packing slips where I would like it to hide the html/H3 text if the custom field doesn’t exist for a product.

    I’ve tried to look for a solution on this support forum and can see similar ones where fields don’t show if no data exists using “if (empty…” or similar but I can’t seem to work that code into the code below.

    If anyone could help I’d really appreciate it.

    Many thanks in advance!

    https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/displaying-a-custom-field/

    add_action( 'wpo_wcpdf_after_order_details', 'wpo_wcpdf_funeral_start_time', 10, 2 );
    function wpo_wcpdf_funeral_start_time ($template_type, $order) {
        $document = wcpdf_get_document( $template_type, $order );
        if ($template_type == 'packing-slip') {
            ?>
    <div>
            <h3>Funeral start time:</h3>
    		<p><?php $document->custom_field('funeral_start_time'); ?></p>
    	<p></p>
    	</div>
            <?php
        }
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @shocksalmighty,

    Please try replacing that code snippet with this:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Displayes the Funeral start time, if it exists 
     */
    add_action( 'wpo_wcpdf_after_order_details', function( $document_type, $order ) {
    	if ( $document_type == 'packing-slip' && ( $funeral_start_time = $order->get_meta( 'funeral_start_time' ) ) ) {
    		?>
    		<div>
    			<h3>Funeral start time:</h3>
    			<p><?php echo $funeral_start_time ?></p>
    		</div>
    		<?php
    	}
    }, 10, 2 );

    Let me know if it worked as you expected!

    Thread Starter shocksalmighty

    (@shocksalmighty)

    Amazing, it works perfectly!

    Thank you so much for taking the time to do this Yordan!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    We are happy to help, @shocksalmighty!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

    Thread Starter shocksalmighty

    (@shocksalmighty)

    No problem Yordan, I have just left a 5 star review for you!

    Many thanks for your help and for providing such great support!

    All the best and keep up the great work!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Wow! Thanks for your 5 star review, @shocksalmighty!

    You made my week! ??

    Let us know if you need anything else ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom field on packing slip for certain products only’ is closed to new replies.