• I want to add a custom field and if that field is empty the invoice prefix stays “WEB-” but if that camp has any value change the prefix to another one like “WEBDNI-“

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @rbtmj2,

    When you say “invoice prefix”, are you talking about the filename of the invoice? Or maybe the invoice number itself that appears in the invoice?

    Thread Starter rbtmj2

    (@rbtmj2)

    The invoice number for example WEB-0001 I want to change WEB for other prefix if a custom field is empty or not

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hello @rbtmj2,

    Please try adding this code snippet to your site:

    add_filter('wpo_wcpdf_document_number_settings','wpo_wcpdf_document_number_variable_prefix',10,2);
    function wpo_wcpdf_document_number_variable_prefix( $number_settings, $document ) {
      if (!empty($document->order) && $document->get_type() == 'invoice') {
        $custom_field =  $document->order->get_meta('custom_field_name');
        if (empty($custom_field)) { // Custom field is empty
          $number_settings['prefix'] = "WEB-";
        } else { // Custom field has a value
          $number_settings['prefix'] = "WEBDNI-";
        }
      }
      return $number_settings;
    }

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Let me know if it works! ??

    Thread Starter rbtmj2

    (@rbtmj2)

    It worked!!!

    Thank you so much

    Thread Starter rbtmj2

    (@rbtmj2)

    Also its possible that the different prefix invoice are count different? I mean if you have WEBID-0004 and the user left the custom filed empty the next invoce is WEB-0001

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change invoice prefix with custom field’ is closed to new replies.