- This topic has 5 replies, 2 voices, and was last updated 5 months, 1 week ago by
David.
-
AuthorPosts
-
October 11, 2022 at 3:18 am #2369675
xinghui
I want to call woocommerce’s mini shopping cart, so I defined a mini shopping cart shortcode myself, I borrowed the code from the Internet, but it did not display correctly after creation? Is there any error please?
my image_url:https://i.postimg.cc/x8T1jXJ3/Lavb-mini-cart-testttcccccc.jpgOctober 11, 2022 at 5:25 am #2369775David
StaffCustomer SupportHi there,
we can’t really support custom development code.
But if you want to share the code you used to create the shortcode i can take a look for any obvious issues.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 11, 2022 at 6:01 am #2369811xinghui
Thank you very much for your help, I use this code, but it doesn’t seem to work
function custom_mini_cart() { echo '<a href="#"> '; echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>'; echo '<div class="basket-item-count">'; echo '<span class="cart-items-count count">'; echo WC()->cart->get_cart_contents_count(); echo '</span>'; echo '</div>'; echo '</a>'; echo '<ul class="dropdown-menu dropdown-menu-mini-cart">'; echo '<li> <div class="widget_shopping_cart_content">'; woocommerce_mini_cart(); echo '</div></li></ul>'; } add_shortcode( '[custom-techno-mini-cart]', 'custom_mini_cart' );
this is the code link I refer to:https://www.codegrepper.com/code-examples/php/mini+cart+woocommerce+shortcode
October 12, 2022 at 4:33 am #2370869David
StaffCustomer SupportI can’t say if this will fix it, but i can see 2 issues.
1. Use of
echo
in a shortcode requires Object Buffering. See here:https://docs.generatepress.com/article/creating-a-shortcode/
2. The
add_shortcode
name should not include the[ square brackets ]
Making those changes your code would look like:
function custom_mini_cart() { ob_start(); echo '<a href="#"> '; echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>'; echo '<div class="basket-item-count">'; echo '<span class="cart-items-count count">'; echo WC()->cart->get_cart_contents_count(); echo '</span>'; echo '</div>'; echo '</a>'; echo '<ul class="dropdown-menu dropdown-menu-mini-cart">'; echo '<li> <div class="widget_shopping_cart_content">'; woocommerce_mini_cart(); echo '</div></li></ul>'; return ob_get_clean(); } add_shortcode( 'custom-techno-mini-cart', 'custom_mini_cart' );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 12, 2022 at 4:58 am #2370895xinghui
Thanks, maybe my function is wrong, I have found a plugin to replace it, still appreciate your kind help, have a nice day
October 12, 2022 at 6:37 am #2370979David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.