Support » Plugin: WooCommerce PDF Invoices & Packing Slips » GSTIN depending on state selected on checkout

  • Resolved tejashreee

    (@tejashreee)


    Hello, I’m using this plugin’s free version and I want to display the GSTIN number in the PDF invoice and the GSTIN will be depending on which state the customer chooses on the checkout page. I don’t have much knowledge of programming. Can you please help me here?

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

    (@yordansoares)

    Hi @tejashreee,

    You can add this code snippet to your site to display your GSTIN number after the billing address:

    /**
     * Show GSTIN number after billing address
     */
    add_action( 'wpo_wcpdf_after_billing_address', 'wpo_wcpdf_show_gstin_number', 10, 2 );
    function wpo_wcpdf_show_gstin_number( $template_type, $order ){
    	if( $template_type == 'invoice' ){		
    		// Change 'gstin_number' for the actual meta key used by the GSTIN number
    		if( $gstin_number = $order->get_meta( 'gstin_number' ) ){ 
    			echo '<br>GSTIN: ' . $gstin_number;
    		}
    	}
    }

    Please note that I used the gstin_number meta key as an example, but you need to replace it by your actual GSTIN number meta key. See Finding WooCommerce custom fields to learn more.

    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 you managed to make it work!

    Thread Starter tejashreee

    (@tejashreee)

    Actually, I don’t want to show GSTIN number after billing address. I want the GSTIN number to change when customers select different states on the checkout page. i.e. if customer selects Delhi then GSTIN will be 1234 and when he/she selects Maharashtra then the GSTIN will be 8956. And I want to show these changed GSTIN numbers in PDF invoice according to the particular state.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Actually, I don’t want to show GSTIN number after billing address.

    If not after billing address, in which place of the invoice do you want to show the GSTIN number? You can take a look at all the available PDF template action hooks to see in which places in the invoice you can add your GSTIN number.

    I want the GSTIN number to change when customers select different states on the checkout page.

    Meanwhile you answer my previous question, I’ll continue adding the GSTIN number after the billing country. Please, replace my previous code for this one, that display the GSTIN number based on the chosen Indian State:

    /**
     * Show GSTIN number based on the choose Indian State
     */
    add_action( 'wpo_wcpdf_after_billing_address', 'wpo_wcpdf_show_gstin_number_based_on_indian_state', 10, 2 );
    function wpo_wcpdf_show_gstin_number_based_on_indian_state( $template_type, $order ){
    	if( $template_type == 'invoice' ){		
    		$billing_country = $order->get_billing_country();
    		if ($billing_country == 'IN') {
    			$billing_state = $order->get_billing_state();			
    			switch ( $billing_state ) {
    				case 'AP': # Andhra Pradesh
    				$gstin_number = '1234';
    				break;
    				case 'AR': # Arunachal Pradesh
    				$gstin_number = '1234';
    				break;
    				case 'AS': # Assam
    				$gstin_number = '1234';
    				break;
    				case 'BR': # Bihar
    				$gstin_number = '1234';
    				break;
    				case 'CT': # Chhattisgarh
    				$gstin_number = '1234';
    				break;
    				case 'GA': # Goa
    				$gstin_number = '1234';
    				break;
    				case 'GJ': # Gujarat
    				$gstin_number = '1234';
    				break;
    				case 'HR': # Haryana
    				$gstin_number = '1234';
    				break;
    				case 'HP': # Himachal Pradesh
    				$gstin_number = '1234';
    				break;
    				case 'JK': # Jammu and Kashmir
    				$gstin_number = '1234';
    				break;
    				case 'JH': # Jharkhand
    				$gstin_number = '1234';
    				break;
    				case 'KA': # Karnataka
    				$gstin_number = '1234';
    				break;
    				case 'KL': # Kerala
    				$gstin_number = '1234';
    				break;
    				case 'LA': # Ladakh
    				$gstin_number = '1234';
    				break;
    				case 'MP': # Madhya Pradesh
    				$gstin_number = '1234';
    				break;
    				case 'MH': # Maharashtra
    				$gstin_number = '1234';
    				break;
    				case 'MN': # Manipur
    				$gstin_number = '1234';
    				break;
    				case 'ML': # Meghalaya
    				$gstin_number = '1234';
    				break;
    				case 'MZ': # Mizoram
    				$gstin_number = '1234';
    				break;
    				case 'NL': # Nagaland
    				$gstin_number = '1234';
    				break;
    				case 'OR': # Odisha
    				$gstin_number = '1234';
    				break;
    				case 'PB': # Punjab
    				$gstin_number = '1234';
    				break;
    				case 'RJ': # Rajasthan
    				$gstin_number = '1234';
    				break;
    				case 'SK': # Sikkim
    				$gstin_number = '1234';
    				break;
    				case 'TN': # Tamil Nadu
    				$gstin_number = '1234';
    				break;
    				case 'TS': # Telangana
    				$gstin_number = '1234';
    				break;
    				case 'TR': # Tripura
    				$gstin_number = '1234';
    				break;
    				case 'UK': # Uttarakhand
    				$gstin_number = '1234';
    				break;
    				case 'UP': # Uttar Pradesh
    				$gstin_number = '1234';
    				break;
    				case 'WB': # West Bengal
    				$gstin_number = '1234';
    				break;
    				case 'AN': # Andaman and Nicobar Islands
    				$gstin_number = '1234';
    				break;
    				case 'CH': # Chandigarh
    				$gstin_number = '1234';
    				break;
    				case 'DN': # Dadra and Nagar Haveli
    				$gstin_number = '1234';
    				break;
    				case 'DD': # Daman and Diu
    				$gstin_number = '1234';
    				break;
    				case 'DL': # Delhi
    				$gstin_number = '1234';
    				break;
    				case 'LD': # Lakshadeep
    				$gstin_number = '1234';
    				break;
    				case 'PY': # Pondicherry (Puducherry)
    				$gstin_number = '1234';
    				break;
    				
    				default:
    				$gstin_number = '';
    				break;
    			}			
    		}
    		if( $gstin_number ){ 
    			echo '<br>GSTIN: ' . $gstin_number;
    		}
    	}
    }

    Please note that I have set 1234 for all the States: you need to update the actual GSTIN number for each one.

    Let me know if it works for you πŸ™‚

    Thread Starter tejashreee

    (@tejashreee)

    I am very grateful to you. It’s working the way I want it to. πŸ™‚ I really appreciate your efforts. Would you please help a little more??
    I want to display this GSTIN number below the shop address or in the footer.

    Thank you so much Yordan πŸ™‚

    Thread Starter tejashreee

    (@tejashreee)

    Hello @yordansoares,

    I have found a solution to this. Thank you soo much. 😊

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I want to display this GSTIN number below the shop address or in the footer.

    To do so, you just need to replace the wpo_wcpdf_after_billing_address action hook with wpo_wcpdf_after_shop_address or wpo_wcpdf_before_footer/wpo_wcpdf_after_footer

    I have found a solution to this. Thank you soo much. 😊

    I’m glad to know that it worked!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

    Thread Starter tejashreee

    (@tejashreee)

    Yes, of course. I would love to. πŸ™‚

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘GSTIN depending on state selected on checkout’ is closed to new replies.