Show Mini cart on homepage

how to add the cart to the home page, the mini cart on the top right corner? I tried the suggestions shared here, but didn't worked very well:

https://premium.wpmudev.org/forums/topic/floating-mini-cart-disappear-after-marketpress-plugin-update#post-1212802

  • Panos

    Hey there Justin ,

    You can try changing line:

    $cart = new MP_Cart();

    to

    $cart = mp_cart();

    As you mentioned you need this only for the home page, so you might need to add a conditional statement checking if is_home() so the final snipped should look like :

    add_filter( 'mp_cart_needed_on_page', function( $cart_needed ){
    
    	if( is_home() ){
    		$cart_needed = true;
    	}
    
    	return $cart_needed;
    
    } );
    
    add_action( 'init', function() {
    
    	if( ! is_home() ){
    		return;
    	}
    
        require_once WP_PLUGIN_DIR . '/marketpress/includes/common/class-mp-product.php';
        require_once WP_PLUGIN_DIR . '/marketpress/includes/common/helpers.php';
        require_once WP_PLUGIN_DIR . '/marketpress/includes/common/class-mp-cart.php';
    
        $cart = mp_cart();
        add_action( 'wp_footer', array( $cart, 'floating_cart_html' ) );
    } );

    Hope this helps!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.