WooCommerce custom mini cart function/shortcode not working
I've been trying to implement the MiniCart in my woocommerce shop, yet without succes.
What I tried is making a custom function and shortcode, and call it in my header.
Here's the code I'm using in my theme functions:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( '[nachtleven-mini-cart]', 'custom_mini_cart' );
So I want to use this to output the mini cart:
<?php echo do_shortcode('nachtleven-mini-cart'); ?>
Yet it always returns a string on the frontend: [custom-mini-cart]
, so it seems like the shortcode isn't working. Am I missing something here? Even a simple echo in the function won't display.
I haven't had any problems with making and using shortcodes before, though this is the first time I'm building with WooCommerce.
Any help or tips would be greatly appreciated as I'm kinda overlooking the problem here.
Thanks =)
php wordpress woocommerce
add a comment |
I've been trying to implement the MiniCart in my woocommerce shop, yet without succes.
What I tried is making a custom function and shortcode, and call it in my header.
Here's the code I'm using in my theme functions:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( '[nachtleven-mini-cart]', 'custom_mini_cart' );
So I want to use this to output the mini cart:
<?php echo do_shortcode('nachtleven-mini-cart'); ?>
Yet it always returns a string on the frontend: [custom-mini-cart]
, so it seems like the shortcode isn't working. Am I missing something here? Even a simple echo in the function won't display.
I haven't had any problems with making and using shortcodes before, though this is the first time I'm building with WooCommerce.
Any help or tips would be greatly appreciated as I'm kinda overlooking the problem here.
Thanks =)
php wordpress woocommerce
add a comment |
I've been trying to implement the MiniCart in my woocommerce shop, yet without succes.
What I tried is making a custom function and shortcode, and call it in my header.
Here's the code I'm using in my theme functions:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( '[nachtleven-mini-cart]', 'custom_mini_cart' );
So I want to use this to output the mini cart:
<?php echo do_shortcode('nachtleven-mini-cart'); ?>
Yet it always returns a string on the frontend: [custom-mini-cart]
, so it seems like the shortcode isn't working. Am I missing something here? Even a simple echo in the function won't display.
I haven't had any problems with making and using shortcodes before, though this is the first time I'm building with WooCommerce.
Any help or tips would be greatly appreciated as I'm kinda overlooking the problem here.
Thanks =)
php wordpress woocommerce
I've been trying to implement the MiniCart in my woocommerce shop, yet without succes.
What I tried is making a custom function and shortcode, and call it in my header.
Here's the code I'm using in my theme functions:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( '[nachtleven-mini-cart]', 'custom_mini_cart' );
So I want to use this to output the mini cart:
<?php echo do_shortcode('nachtleven-mini-cart'); ?>
Yet it always returns a string on the frontend: [custom-mini-cart]
, so it seems like the shortcode isn't working. Am I missing something here? Even a simple echo in the function won't display.
I haven't had any problems with making and using shortcodes before, though this is the first time I'm building with WooCommerce.
Any help or tips would be greatly appreciated as I'm kinda overlooking the problem here.
Thanks =)
php wordpress woocommerce
php wordpress woocommerce
edited Nov 14 '18 at 13:19
Jasper Janssen
asked Nov 14 '18 at 13:06
Jasper JanssenJasper Janssen
265
265
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You add a wrong hook for the shortcode tag when you call add_shortcode( $tag , $func ); by adding name inside square brackets .Your code should be link:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( 'nachtleven-mini-cart', 'custom_mini_cart' );
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300955%2fwoocommerce-custom-mini-cart-function-shortcode-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You add a wrong hook for the shortcode tag when you call add_shortcode( $tag , $func ); by adding name inside square brackets .Your code should be link:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( 'nachtleven-mini-cart', 'custom_mini_cart' );
add a comment |
You add a wrong hook for the shortcode tag when you call add_shortcode( $tag , $func ); by adding name inside square brackets .Your code should be link:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( 'nachtleven-mini-cart', 'custom_mini_cart' );
add a comment |
You add a wrong hook for the shortcode tag when you call add_shortcode( $tag , $func ); by adding name inside square brackets .Your code should be link:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( 'nachtleven-mini-cart', 'custom_mini_cart' );
You add a wrong hook for the shortcode tag when you call add_shortcode( $tag , $func ); by adding name inside square brackets .Your code should be link:
function custom_mini_cart()
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
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( 'nachtleven-mini-cart', 'custom_mini_cart' );
edited Nov 14 '18 at 13:51
answered Nov 14 '18 at 13:45
Ovidiu BarzaghideanuOvidiu Barzaghideanu
863
863
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300955%2fwoocommerce-custom-mini-cart-function-shortcode-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown