Skip to content

Instantly share code, notes, and snippets.

@mikemcalister
Created February 2, 2016 23:55
Show Gist options
  • Save mikemcalister/fc6dc6939e82d96390fe to your computer and use it in GitHub Desktop.
Save mikemcalister/fc6dc6939e82d96390fe to your computer and use it in GitHub Desktop.
/**
* Unhook the cart widget/icon
*
*/
function checkout_remove_cart_icon() {
remove_filter( 'wp_nav_menu_items', 'checkout_add_cart_widget_to_menu', 10, 2 );
add_filter( 'wp_nav_menu_items', 'checkout_add_revised_cart_widget_to_menu', 1, 2 );
}
add_action( 'init', 'checkout_remove_cart_icon' );
/**
* Add the cart widget/icon back with new arrangement
*
*/
function checkout_add_revised_cart_widget_to_menu( $items, $args ) {
if ( 'primary' != $args->theme_location )
return $items;
ob_start();
$widget_args = array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
);
$widget = the_widget( 'edd_cart_widget', array( 'title' => '' ), $widget_args );
$widget = ob_get_clean();
$link = sprintf( '<li class="current-cart menu-item menu-item-has-children"><a href="%s"><span class="edd-cart-quantity">%d</span></a><ul class="sub-menu"><li class="widget">%s</li></ul></li>', get_permalink( edd_get_option( 'purchase_page' ) ), edd_get_cart_quantity(), $widget );
return $items . $link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment