Displaying gst through custom code not working as the action hook is not know

This topic has 16 replies, 2 voices, and was last updated 12 months ago ago by Andrew Mitchell

  • Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 20, 2024 at 22:08

    i want to display gst on the pop up cart also can you be of help to provide me with the hook or piece of snnipet for the same

    gst to be shown just above subtotal give the action hook you used

    Please, contact administrator
    for this information.
    Files is visible for topic creator and
    support staff only.
    15 Answers
    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 20, 2024 at 22:09

    i want to display gst in your mini-cart that floats on right just above subtotal.

    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 21, 2024 at 11:58

    Hi can someone help me with this too thanks

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    June 21, 2024 at 13:15

    Hello, Aulakh, Sam,

    Thank you for reaching out to us with your request.

    To add GST to the mini-cart in WooCommerce, you can use the following filter in your child theme functions.php file:

    add_action( 'woocommerce_widget_shopping_cart_total', 'display_gst_cart', 101 );

    This code snippet will help you integrate GST into the total displayed in your WooCommerce mini-cart. If you need further assistance or have any more questions, please feel free to ask.

    Best Regards,
    8Theme’s Team

    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 21, 2024 at 13:17

    .

    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 21, 2024 at 13:22

    Can GST be on top of subtotal ?

    Files is visible for topic creator and
    support staff only.
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    June 21, 2024 at 13:23

    Certainly, you can add the following lines right after the next line in your code:

    add_action( 'woocommerce_review_order_before_order_total', 'display_gst_checkout' );

    It will look like this:

    // Display GST in cart and checkout page
    add_action( 'woocommerce_cart_totals_before_order_total', 'display_gst_cart' );
    add_action( 'woocommerce_review_order_before_order_total', 'display_gst_checkout' );
    add_action( 'woocommerce_widget_shopping_cart_total', 'display_gst_cart', 101 );

    Best Regards,
    8Theme’s Team

    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 21, 2024 at 13:25
    // Display GST in cart and checkout page
    add_action( 'woocommerce_cart_totals_before_order_total', 'display_gst_cart' );
    add_action( 'woocommerce_review_order_before_order_total', 'display_gst_checkout' );
    add_action( 'woocommerce_widget_shopping_cart_total', 'display_gst_cart', 101 );

    still showing next to it on right not above

    Files is visible for topic creator and
    support staff only.
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    June 21, 2024 at 13:32

    Could you please provide the link to the website where you are implementing GST? We will need to add custom CSS, which is unique for each site.

    Thank you for your assistance.

    Best regards,

    8Theme’s Team

    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 21, 2024 at 13:36
    // Display GST in cart and checkout page
    add_action( 'woocommerce_cart_totals_before_order_total', 'display_gst_cart' );
    add_action( 'woocommerce_review_order_before_order_total', 'display_gst_checkout' );
    add_action( 'woocommerce_widget_shopping_cart_total', 'display_gst_cart', 101 );
    
    function display_gst_cart() {
        $gst_rate = 0.09; // GST rate of 9%
        $cart_total = WC()->cart->subtotal;
        $gst_amount = $cart_total * $gst_rate;
        ?>
        <tr class="gst">
            <th><?php _e( 'GST', 'text-domain' ); ?></th>
            <td data-title="<?php _e( 'GST', 'text-domain' ); ?>"><?php echo wc_price( $gst_amount ); ?></td>
        </tr>
        <?php
    }
    
    function display_gst_checkout() {
        $gst_rate = 0.09; // GST rate of 9%
        $cart_total = WC()->cart->subtotal;
        $gst_amount = $cart_total * $gst_rate;
        ?>
        <tr class="gst">
            <th><?php _e( 'GST', 'text-domain' ); ?></th>
            <td data-title="<?php _e( 'GST', 'text-domain' ); ?>"><?php echo wc_price( $gst_amount ); ?></td>
        </tr>
        <?php
    }

    this is current code but i want to enable GST just above subotal so it will display like

    GST
    Subtotal

    Please contact administrator
    for this information.
    Files is visible for topic creator and
    support staff only.
    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 21, 2024 at 13:42

    Andrew Mitchell were you able to login ?

    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 21, 2024 at 14:19

    Is someone working on the stagging site dear authors ?

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    June 21, 2024 at 14:20

    Yes, I can login also, you need to add next code to child theme functions.php file:

    add_action( 'woocommerce_widget_shopping_cart_total', 'display_gst_mobile_cart', 10 );
    
    function display_gst_mobile_cart() {
    	$gst_rate = 0.09; // GST rate of 9%
    	$cart_total = WC()->cart->subtotal;
    	$gst_amount = $cart_total * $gst_rate;
    	?>
        <span class="gst gst-mobile-cart">
            <span><?php _e( 'GST', 'text-domain' ); ?></span>
            <span data-title="<?php _e( 'GST', 'text-domain' ); ?>"><?php echo wc_price( $gst_amount ); ?></span>
        </span>
    	<?php
    }

    and remove the next code
    add_action( 'woocommerce_widget_shopping_cart_total', 'display_gst_cart', 101 );

    Implementing this code will enable us to continue with the setup and ensure proper functionality of the GST display on mobile carts.

    Please let me know when you do it

    Best Regards,
    8Theme’s Team

    Avatar: Aulakh, Sam
    Aulakh, Sam
    Participant
    June 21, 2024 at 14:24

    its showing gst on left and subtotal on right

    i want it like this:

    GST

    SUBTOTAL

    not like this GST SUBTOTAL

    alignment is not correct it should be gst then below it should be subtotal

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    June 21, 2024 at 14:42

    Please check,

    The changes in functions.php were necessary to set the correct structure for your case,
    after which the following custom CSS was added to the field Customizer->Theme custom css -> Global.

    /* GTS for mini cart */
    .cart-widget-subtotal.woocommerce-mini-cart__total.total{
        display: inline-block!important;
    }
    .gst.gst-mobile-cart{
    width: 100%;
        display: inline-block;
        text-align: left;
    }
    .gst.gst-mobile-cart [data-title="GST"]{
    		float: right;
    }
    
    .cart-widget-subtotal.woocommerce-mini-cart__total.total .small-h{
        display: inline-block;
        float: left;
    }

    Best Regards,
    8Theme’s Team

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    June 21, 2024 at 15:11

    Dear Aulakh, Sam,

    We hope you’re reveling in the experience our theme brings! Your enthusiasm is what fuels our passion. Would you be so kind as to channel that energy into a 5-star rating on ThemeForest? Your feedback is the spark that lights our way!

    Click here to spread the love: https://themeforest.net/downloads

    Thank you for being an integral part of our journey!

    Best Regards,
    The 8Theme Team

  • Viewing 16 results - 1 through 16 (of 16 total)

The issue related to '‘Displaying gst through custom code not working as the action hook is not know’' has been successfully resolved, and the topic is now closed for further responses

Helpful Topics

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.