Hi
I was looking for the same thing and found the following in another thread about outputting widgets in template files:
<?php
$instance = array("title" => "", "number" => 1);
$args = array("title" => "My Widget", "before_title" => "", "after_title" => "");
$sb = new WooCommerce_Widget_DropdownCart();
$sb->number = $instance['number'];
$sb->widget($args,$instance);
?>
This works for me! You can fill the title, before_title and after_title if you wish. Like:
$instance = array("title" => "MyTitle", "number" => 1);
$args = array("title" => "My Widget", "before_title" => "<h2>", "after_title" => "</h2>");
John
(@johnsundialstudioscom)
I somewhat new to WordPress (been using Joomla for 3 years and can do almost anything with it) but I seem to have a mental block when it comes to adding new widget positions to WordPress.
My theme does not have, by default, a position in the header area for the cart. I have tried adding
register_sidebar(array(
'name' => 'MiniCart',
'id' => 'minicart',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
to my functions.php file and adding
<?php dynamic_sidebar('minicart'); ?>
to my header.php file.
Is the code from nsunberg above a better solution for me? If there is a post somewhere else that will give me some better guidance please post it for me!
Thanks,
John
The code I supplied in my previous post is used to output a specific widget in a template file, in this case the Dropdown Cart Widget.
You can do this in two ways (that I am aware of):
1. Use the code I posted earlier, just put it wherever you want it to be.
2. Register a widget area in your functions.php and place a code snippet where you want to show it. Then go to Appearance -> Widgets and drag-and-drop the Dropdown Cart Widget to the widget area you just created.
You can read more about widgets under:
WordPress Widgets
Widgetizing Themes
The following code is taken from “Widgetizing themes” and slightly edited. Put this code into your functions.php file.
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Woocommerce Dropdown Cart',
'id' => 'wc_dropdown_cart',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
Then put the following code wherever you want the dropdown cart to shop up. Maybe in header.php?
<?php
if ( dynamic_sidebar('wc_dropdown_cart') ) :
else : ?>
<?php endif; ?>
Remember that you have to activate the widget under Appearance -> Widgets.