Hiding link "go add some" in empty cart

Hi,

When im using the global cart function and empty my cart on the main site, then i get a message about cart is empty and i should go and add some products.
See my attached picture.

When clicking on this link, i get redirected to the shop, which actually having no products, because this is main site.
So i want to hide the link on the main site or maybe change the link, so its link to the marketplace instead.

Is there a way to do this?

Best regards,

    • Mikkel

      Hi Luís,

      Some of this information helped me.

      I was able to change the URL it get redirected to, so it now send user to marketplace.
      But the way its show up have change. See before and after picture. One with blue area is before adding the code to functions.php file.

      Also i want to know, if i can do the same with the "Continue shopping" button in cart, when there is product in it, so it send people to marketplace instead of the shop pages on main site.

      BR

  • Ash

    Hello Mikkel

    See before and after picture. One with blue area is before adding the code to functions.php file.

    Your screenshot is not attached, would you please try again? I have checked the cart page and it looks like the following:

    To replace the URL of continue shopping button, you need to know the page ID of product page, then you can try the following code:

    add_filter( 'page_link', function( $link, $post_id, $sample ) {
            $product_page_id = 123;
            if( $post_id == $product_page_id )
            {
                    $link = 'My Custom Link';
            }
    
            return $link;
    } );

    Change $product_page_id and $link with correct value.

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

    • Mikkel

      Hi Ash,

      Sorry for not attach the image. Here is one, that showing the site now after adding that code again, as you see the blue box is gone after adding the first code.

      For the one changing "Continue Shopping" im not sure how this should work.
      Where can i find the product page id?
      The button i talking about with Continue Shopping is the one shown in cart, where customer can go back and shop or go to check out.

      Best regards,

  • Ash

    Hello Mikkel

    The images are still not attached, unfortunately. You can use any third party service like dropbox or screencast etc if you are having issues with upload. You can even upload to your site and send me a link of the image.

    Your product page ID is 9, so the code should be:

    add_filter( 'page_link', function( $link, $post_id, $sample ) {
            $product_page_id = 9;
            if( $post_id == $product_page_id )
            {
                    $link = 'http://kreativeshop.dk/markedsplads';
            }
    
            return $link;
    } );

    Have a good day!

    Cheers
    Ash

  • Luís

    Hi Mikkel ,

    Hope you're doing well today!

    I made some tests in my install and to change the link of the empty cart message and keep the same style, please try this:

    add_filter( 'mp_cart/no_items_message', 'custom_no_items_message' );
    
    function custom_no_items_message() {
    
      $url = site_url('/your-new-page');
        $message = '<div class="mp_cart_empty">';
    
    	$message .= '<p class="mp_cart_empty_message">';
    
        $message .= sprintf( __( 'There are no items in your cart - <a href="%s">go add some</a> !', 'mp' ), $url );
    
        $message .= '</p><!-- end mp_cart_empty_message -->';
    
        $message .= '</div><!-- end mp_cart_empty -->';
    
        return $message;
    }

    Also, to change the link in the "Continue Shopping?" button, please try this code:

    add_action( 'wp_footer', 'custom_continue_btn_message' );
    function custom_continue_btn_message() {
        ?>
        <script type="text/javascript">
          jQuery(document).ready(function() {
            jQuery(".mp_button-continue-shopping").attr( "href", "<?php echo site_url('/your-new-page'); ?>" );
          });
          jQuery(document).ajaxSuccess(function() {
            jQuery(".mp_button-continue-shopping").attr( "href", "<?php echo site_url('/your-new-page'); ?>" );
    		});
        </script>
        <?php
    }

    Note: In both snippets, it was used "/your-new-page" as an example. Please change it to the page you want.

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • Luís

    Hi Mikkel ,

    Hope you're doing well today!

    Sorry, it was my falt. If you want both links always redirect the user to the marketplace in the main site, can you try replace the code given by:

    function custom_no_items_message() {
    
      $url = 'http://my.site.com/marketplace';
        $message = '<div class="mp_cart_empty">';
    
    	$message .= '<p class="mp_cart_empty_message">';
    
        $message .= sprintf( __( 'There are no items in your cart - <a href="%s">go add some</a> !', 'mp' ), $url );
    
        $message .= '</p><!-- end mp_cart_empty_message -->';
    
        $message .= '</div><!-- end mp_cart_empty -->';
    
        return $message;
    }
    
    add_action( 'wp_footer', 'custom_continue_btn_message' );
    function custom_continue_btn_message() {
     $url = 'http://my.site.com/marketplace';
        ?>
        <script type="text/javascript">
          jQuery(document).ready(function() {
            jQuery(".mp_button-continue-shopping").attr( "href", "<?php echo $url; ?>" );
          });
          jQuery(document).ajaxSuccess(function() {
            jQuery(".mp_button-continue-shopping").attr( "href", "<?php echo $url; ?>" );
    		});
        </script>
        <?php
    }

    Replace the URL used in "$url" variable to your Marketplace page URL.

    Cheers, Luís