• Resolved jarekt

    (@jarekt)


    I have added a checkbox “I want an invoice”
    If I use code:

    add_filter( 'wpo_wcpdf_document_is_allowed', 'wpo_wcpdf_allow_invoice_if_checkbox_is_selected', 10, 2 );
    function wpo_wcpdf_allow_invoice_if_checkbox_is_selected( $allowed, $document ) {
    if ( $document->exists() ) {
    return $allowed;
    }
    if ( $document->order && $document->get_type() == 'invoice') {
    $checkbox = $document->order->get_meta( '_if_invoice' );
    $allowed = wc_string_to_bool( $checkbox ); 
    }
    return $allowed;
    }

    The invoice is created and sent only if I check the checkbox
    But then I can’t add the invoice manually in the orders panel.
    I would like to be able to add an invoice manually sometimes.

    The code

    add_filter( 'wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_send_invoice_on_customer_request', 100, 4 );
    function wpo_wcpdf_send_invoice_on_customer_request( $condition, $order, $status, $template_type ) {
    if ( $template_type == 'invoice' ) {
    $condition = $order->get_meta( '_if_invoice' ) == 1 ? true : false;
    }
    }

    doesn’t work at all for me, it neither attaches nor creates an invoice regardless of the checkbox.
    I found both snippets here, but the second one doesn’t work and the first one doesn’t allow adding an invoice in the panel. Is there any solution?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @jarekt:

    Try updating the second code snippet with this one:

    add_filter( 'wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_send_invoice_on_customer_request', 100, 4 );
    function wpo_wcpdf_send_invoice_on_customer_request( $condition, $order, $status, $template_type ) {
    	if ( $template_type == 'invoice' ) {
    		$condition = $order->get_meta( '_if_invoice' ) == 1 ? true : false;
    	}
    	return $condition;
    }

    Let me know if it worked!

    Thread Starter jarekt

    (@jarekt)

    OK, everything works great! The whole system works great together!
    Thank you for your help!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m glad to hear that, @jarekt! ??

    Let us know if you need anything else! ??

    Thread Starter jarekt

    (@jarekt)

    Probably PRO for Credit Invoice ??
    But free version is awesome ??

    Plugin Contributor Yordan Soares

    (@yordansoares)

    The Professional extension indeed have very nice extra tools and settings, but I’m very glad to hear that our free main plugin is already awesome enough for you! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sending an invoice only when the checkbox is checked – problem’ is closed to new replies.