I am trying to add a custom WooCommerce cart link with contents count and total cost as the last option in a menu.
This is my code that I am currently using:
add_filter('wp_nav_menu_header-menu_items','custom_minicart_in_main_menu', 10, 2);
function custom_minicart_in_main_menu( $menu, $args) {
$minicart_link = '<a class="custom-minicart" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( "View Your Cart" ); ?>"><?php echo sprintf ( _n( "%d item", "%d items", WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>';
return $menu . $minicart_link;
}
Problem is, the only thing that is shown as a result is:
">cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - cart->get_cart_total(); ?>
The result should be:
Cart (#number of items) - $total cost of all products (subtotal using wc_price)
So, like this:
Cart (4) - $78.50
How can I adjust my code so that I get the desired result?