• Resolved josede

    (@josede)


    I want to modify the invoice prefix based on specific Product category. If its possible the count number exit from the normal loop. (I dont care the number)

    I have a little code, but doesnt work. I modified but never work.

    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') {
        $billing_country = $document->order->get_billing_country();
        $eu_countries = WC()->countries->get_european_union_countries('eu_vat');
        $is_eu_country = in_array($billing_country, $eu_countries);
        if ($billing_country == 'ES') { // Customer from Spain
          $number_settings['prefix'] = "ES/";
        } elseif($is_eu_country) { // Customer from another EU country
          $number_settings['prefix'] = "EU/";
        }
      }
      return $number_settings;
    }
    • This topic was modified 3 years, 7 months ago by josede.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @josede

    Please try the code below inside your theme functions.php file:

    add_filter( 'wpo_wcpdf_format_document_number', function( $formatted_number, $number, $document, $order ) {
    	if ( ! empty( $order = $document->order ) && $document->get_type() == 'invoice' ) {
    		$billing_country = $order->get_billing_country();
    		$eu_countries    = ! empty( WC()->countries ) && is_callable( array( WC()->countries, 'get_european_union_countries' ) ) ? WC()->countries->get_european_union_countries( 'eu_vat' ) : null;
    		
    		if( in_array( $billing_country, $eu_countries ) ) {
    			if ( $billing_country == 'ES' ) { // Customer from Spain
    				$prefix = 'ES/';
    			} else {                          // Customer from another EU country
    				$prefix = 'EU/';
    			}
    
    			$formatted_number = $prefix . $number->number;
    		}
    	}
    	return $formatted_number;
    }, 10, 4 );

    If you never worked with actions/filters, please read this documentation page: How to use filters

    Thread Starter josede

    (@josede)

    Thx! But where can I choose the specific category?

    Plugin Contributor Darren Peyou

    (@dpeyou)

    Since this topic is answered here: https://www.ads-software.com/support/topic/change-invoice-number-logo-based-on-product-category/?view=all
    …I am going to mark this as resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Condition prefix based on product category’ is closed to new replies.