• Resolved anonymous2k20

    (@anonymous2k20)


    Hello!

    I am trying to add the state code in numerical format as it is mandatory for the GST invoices. I have tried adding a function which would map the state code to it’s numerical value but it isn’t working.

    For example,

    If the state is Delhi. I want the State code to be 7, in the invoice, but the default value is fetching the two letter version of the state and I am unable to figure out the process to add additional variable for the same.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter anonymous2k20

    (@anonymous2k20)

    function set_global_field_key() {
    	$billing_state_code = get_field('billing_state_code');
    	if($billing_state_code == 'DL'){
    		$numeric_state_code = 07;
    	}
    	update_option('numeric_state_code', $numeric_state_code);
    }
    
    add_action('wpi_invoice_information_meta', 'set_global_field_key');

    I have tried this too but the value of numeric_state_code is not being updated. Any idea how to achieve this?

    Plugin Contributor dwpriv

    (@dwpriv)

    @anonymous2k20

    wpi_invoice_information_meta is not a filter of ours. Are you using a different invoice plugin? If this is a typo, you can try using your code in a filter of ours like wpo_wcpdf_after_billing_address. You can see more of our filters here and here.

    Thread Starter anonymous2k20

    (@anonymous2k20)

    Updated the hook with the one you suggested. The code is still not working. I have tried fetching the field key numeric_state_code in the customisation section of the plugin but it doesn’t seem to be fetching the same. Could you please suggest any solutions? @dwpriv

    Plugin Contributor dwpriv

    (@dwpriv)

    @anonymous2k20

    could you share your code here, please?

    Thread Starter anonymous2k20

    (@anonymous2k20)

    This is the code I’ve added in the functions.php file of my child theme,

    function set_global_field_key() {
    	$billing_state_code = get_field('billing_state_code');
    	if($billing_state_code == 'DL'){
    		$numeric_state_code = 07;
    	}
    	update_option('numeric_state_code', $numeric_state_code);
    }
    
    add_action('wpo_wcpdf_after_billing_address', 'set_global_field_key', 10, 2);

    The code I’ve added in the customisation tab of the plugin

    State code: {{numeric_state_code}}

    What I’m trying to achieve?

    I am trying to get the billing_state_code from the individual order and based on the state I would like to assign a numerical which will be printed below the billing address in the invoice. The code is only a sample, I will be adding the numerical for 28 states in India. If you could please guide me that would be great! @dwpriv

    Plugin Contributor dwpriv

    (@dwpriv)

    @anonymous2k20

    You can print the state code to the invoice once you’ve gotten it’s value. Here’s an example:

    `
    
    function set_global_field_key() {
    
        $billing_state_code = get_field('billing_state_code');
    
        if($billing_state_code == 'DL'){
    
            $numeric_state_code = 07;
    
        }
    
        update_option('numeric_state_code', $numeric_state_code);
    
        echo '<br>State Code: ' . $numeric_state_code . '<br>';
    
    }
    
    add_action('wpo_wcpdf_after_billing_address', 'set_global_field_key', 10, 2);
    
    `

    Thread Starter anonymous2k20

    (@anonymous2k20)

    The above answer did not work, but on the brighter side, using your inputs, I have found the solution for the same.

    add_action('wpo_wcpdf_after_billing_address', 'set_global_field_key', 10, 2);
    function set_global_field_key($document_type, $order) {
    	$tax_order = $order->get_type() == 'shop_order_refund' ?  wc_get_order( $order->get_parent_id() ) : clone $order;
        $billing_state = $tax_order->get_billing_state();
        if($billing_state == "TS"){
            $numeric_state_code = "36";
        }
    	if($billing_state == "DL"){
    		$numeric_state_code = "07";
    	}
        update_option('numeric_state_code', $numeric_state_code);
        echo '<br>State Code: ' . $numeric_state_code . '<br>';
    }

    Thank you so much for pointing me in the right direction! @dwpriv

    Plugin Contributor dwpriv

    (@dwpriv)

    @anonymous2k20

    Glad to see the issue is resolved ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add state code numerical to the invoices’ is closed to new replies.