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
This topic has 16 replies, 2 voices, and was last updated 12 months ago ago by Andrew Mitchell
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
i want to display gst in your mini-cart that floats on right just above subtotal.
Hi can someone help me with this too thanks
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
.
Can GST be on top of subtotal ?
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
// 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
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
// 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
Andrew Mitchell were you able to login ?
Is someone working on the stagging site dear authors ?
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
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
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
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
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