• Resolved crauser

    (@crauser)


    Hello,

    is it possible to generate an invoice when the order changes to completed only if the “Company name” field is filled in? At the moment I have this code but it is not working.

    add_filter( ‘wpo_wcpdf_custom_attachment_condition’, ‘wpo_wcpdf_invoice_attachment_condition’, 100, 4 );
    function wpo_wcpdf_invoice_attachment_condition( $condition, $order, $status, $template_type ) {
    // only apply condition to invoices
    if ($template_type == ‘invoice’) {
    $billing_company = $order->get_billing_company();
    // do not attach invoice if billing company is not filled in
    if (empty($billing_company)) {
    $condition = false;
    }
    }

    return $condition;
    }

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

    (@yordansoares)

    Hello @crauser,

    Since v2.2.10 we introduced the wpo_wcpdf_document_is_allowed filter hook that it’s more effective than the one you’re using in your code above.

    Try with this code snippet instead:

    add_filter( 'wpo_wcpdf_document_is_allowed', 'wpo_wcpdf_invoice_attachment_condition', 10, 2 );
    function wpo_wcpdf_invoice_attachment_condition( $allowed, $document ) {
      if ( $order = $document->order ) {
        if ($document->type == 'invoice') {
          $allowed = empty( $order->get_billing_company() ) ? false : true;
        }
      }
      return $allowed;
    }

    Let me know if it works!

    Thread Starter crauser

    (@crauser)

    Hi, I’ll try it out and get back to you shortly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Generate invoice only when company name field is filled in’ is closed to new replies.