• Resolved marlonsabala

    (@marlonsabala)


    hey guys,

    I’ve tried to follow your instructions to add an extra field (if the user did fill it) on the invoice.

    add_filter( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_add_NIF', 10, 2 );
    function wpo_wcpdf_add_tax_id( $template_type, $order ) {
    	if ( $template_type == 'invoice' ) {
    		echo "<tr><td>This should</td><td>print no matter what</td></tr>";
    		$nif = $order->get_meta( 'billing_nif' );
    		if ($nif) {
    			echo "<tr><td>NIF / NIPC:</td><td>{$nif}</td></tr>";
    		}
    	}
    }

    This is what I have, but nothing comes up. I delete and recreate the PDF but no luck.

    Is there something I’m missing?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    your function name and filter callback don’t match: wpo_wcpdf_add_NIF vs wpo_wcpdf_add_tax_id.

    Thread Starter marlonsabala

    (@marlonsabala)

    That was pretty silly. thanks.

    Unfortunately it still doesnt seem to do anything.

    add_filter( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_add_NIF', 10, 2 );
    function wpo_wcpdf_add_NIF( $template_type, $order ) {
    	if ( $template_type == 'invoice' ) {
    		echo "<tr><td>This should</td><td>print no matter what</td></tr>";
    		$nif = $order->get_meta( 'billing_nif' );
    		if ($nif) {
    			echo "<tr><td>NIF / NIPC:</td><td>{$nif}</td></tr>";
    		}
    	}
    }
    Plugin Contributor Ewout

    (@pomegranate)

    Is that not printing the “This should” line either? Where did you put this filter exactly? Are you sure you are using “WooCommerce PDF Invoices & Packing Slips”, version 2.3.5?

    Thread Starter marlonsabala

    (@marlonsabala)

    Got it! Another silly mistake.

    Thanks for your help.

    • This reply was modified 5 years, 4 months ago by marlonsabala.
    Plugin Contributor Ewout

    (@pomegranate)

    wpo_wcpdf_after_order_data is an action, can you try using add_action instead? Note that this is restricted to the Invoice too. Other than that, I have no idea either…

    Thread Starter marlonsabala

    (@marlonsabala)

    Thanks again,

    Is there a way of getting it to show under the user details instead of on the right side?

    Plugin Contributor Ewout

    (@pomegranate)

    Thread Starter marlonsabala

    (@marlonsabala)

    Perfect!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Cannot add new field to template’ is closed to new replies.