• Resolved vgnavada

    (@vgnavada)


    I am using a Theme for a Hotel Booking Website which internally uses WooCommerce Checkout for Payment Processing.

    We have to add hotels & rooms separately in the options given by them (Not directly as Woo Product) & then the theme dynamically creates the Hotel as a Temporary WooCommerce Product when a visitor clicks on BOOK NOW and even the TAX is also managed by WooCommerce itself.

    The issue I face is: In India, There are multiple TAX (GST) rate slabs for Hotel Room Rent depending on Per Night Price.

      If the per night price is < = INR 1000: The GST percentage is 0%
      If it is from INR 1001 to INR 7500: The GST is 12%
      If it is more than INR 7500: The GST is 18%

    I referred to this https://kraftpixel.com/gst-india-setup-woocommerce-wordpress/ where they have explained that we can do this by creating different tax classes as per our requirement and edit the products manually and update its respective tax class.

    But If we have more than one room inside a hotel, The theme creates more than one temporary woo-commerce product, and updating their class for the same has become a very troublesome process.

    So I was thinking, What if programmatically check the PER NIGHT PRICE (which in our case is the WooCommerce Product Price) and depending on that Call its respective Tax Class in the Cart / Checkout Page?

    I also referred: https://stackoverflow.com/questions/47379965/add-custom-tax-value-at-woocommerce-checkout where they are programmatically calculating the Tax Rate like this:

    // Auto Add Tax Depending On Room Per Night Price
    add_action( 'woocommerce_cart_calculate_fees','auto_add_tax_for_room', 10, 1 );
    function auto_add_tax_for_room( $cart ) {
        if ( is_admin() && ! defined('DOING_AJAX') ) return;
      
        $percent = 18;
    
        // Calculation
        $surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percent / 100;
    
        // Add the fee (tax third argument disabled: false)
        $cart->add_fee( __( 'TAX', 'woocommerce')." ($percent%)", $surcharge, false );
    }

    How do I extend this code and call the respective WooCommerce Class here? Something like this?

    $price = get_post_meta( get_the_ID(), '_regular_price', true);
      if { ( ' $price' <= 1000 )
             tax class = ZERO RATES; 
        elseif
        {( ' $price' > 1001 && <7500 )
             tax class= GST 12% RATES; }
        else
        {( ' $price' > 7501)
            tax class = GST 18% RATES; }

    Please guide me!

    • This topic was modified 4 years, 1 month ago by vgnavada.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support mouli a11n

    (@mouli)

    @vgnavada
    This is a fairly complex development topic. I’m going to leave it open for a bit longer to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    I hope that helps you to figure it out.
    Feel free to get back to us if you have further questions.

    Mike W

    (@nixiack8)

    Hi @vgnavada,

    Looking into this, indeed this is a complex development topic, or even project.

    But If we have more than one room inside a hotel, The theme creates more than one temporary woo-commerce product, and updating their class for the same has become a very troublesome process.

    This is intriguing since it is said that the theme dynamically creates the booking automatically – it is not driven by a plugin such as WooCommerce Bookings which can set a tax class per product.

    In this case since it is dynamically created by the theme, I would see if that code can be placed in the theme with the theme developer itself as custom, perhaps in a Child theme if one is not set already. For the last item/question:

    How do I extend this code and call the respective WooCommerce Class here? Something like this?

    Tax classes for function calls are covered at this link. Use this for assistance when talking with the theme developer ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How To Call WooCommerce Tax Classes Programatically?’ is closed to new replies.