• Resolved leroy

    (@leroytuttle)


    Hi,
    Nobody seems can answer this question as I cannot find anything out there in internet land on this, not even stackoverflow. I had a simple PHP 2 liner that I got from someone on stackoverflow that worked, however my site crashed and I had to reload the theme and lost it.

    I’m looking for a simple PHP code for my function.php file to change the empty cart page. My previous one that I lost had a whole image over the page which had a picture of a cart and custom message. It was great, I now have the classic woo page with the your cart is empty message. The divi link that people send me doesn’t work as I tried that.
    Also I get this response which I don’t understand about folders.

    Just create a folder called “woocommerce” inside your child theme/ theme
    Inside “woocommerce” folder create folder called “cart” and copy the file cart-empty.php from woocommerce (plugin) > templates > cart and paste inside your child theme/theme > woocommerce > cart
    Then design the template as you want.
    Note: if you are good at code then you can try the above steps.

    I have no empty-cart php in my theme editor.

    this does nothing

    function cart_empty_redirect_to_shop() {
      global $woocommerce, $woocommerce_errors;
    
    if ( is_cart() && sizeof($woocommerce->cart->cart_contents) == 0) { 
            wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); 
         exit;
        }
    }
    add_action( 'template_redirect', 'cart_empty_redirect_to_shop' );

    it leaves the word CART on my page.

    thanks for reading..
    Leroy

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hi @leroytuttle

    From your description I see you have already explored several avenues to find a solution to this requirement, however, the solutions suggested from several sources didn’t help achieve the desired outcome.

    We recommend getting in touch with one of the services on our Customizations page: https://woocommerce.com/customizations/

    We can also recommend the following places for development-oriented questions:

    Kindly be informed that support for complex custom coding is beyond the scope of support we are able to provide in this forum. This particular forum is for questions that are related to the WooCommerce core features.

    Nevertheless, I’m going to leave this thread open for a bit to see if anyone is able to chime in to help you out here.

    Thread Starter leroy

    (@leroytuttle)

    Thank you Margret I check out your info. Did try the facebook group to join but they refused me, after I said I wanted to learn about this platform.

    • This reply was modified 3 years, 5 months ago by leroy.

    Hi @leroytuttle

    Did try the facebook group to join but they refused me, after I said I wanted to learn about this platform.

    I’m sorry for that. I recommend that you try asking once again, explaining that you’re looking for assistance on a store customization.

    That said, you should be able to remove the default empty cart message, and replace it with an image, by adding the following custom code:

    // Change empty cart page - https://wordpress.org/support/?p=15772130
    remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
    add_action( 'woocommerce_cart_is_empty', 'custom_empty_cart_message', 10 );
    function custom_empty_cart_message() {
        $html  = '<img src="https://www.site/img.jpg" alt="">';
        echo $html;
    }


    (Replace https://www.site/img.jpg with your image URL)

    You can either add it to your theme’s function.php file, or use a plugin such as Code Snippets:
    https://br.wordpress.org/plugins/code-snippets/

    Best

    Thread Starter leroy

    (@leroytuttle)

    Thanks Berg I’ll check it out and see if it works

    Thread Starter leroy

    (@leroytuttle)

    Nope it does nothing.. thanks again

    Hi @leroytuttle

    On a default, up-to-date WooCommerce installation, using a standard theme such as Storefront, and with no conflicting plugins, the code provided does work to remove the default empty cart message and replace it with an image.
    Upon testing, it functioned as expected on my end. Please see the screenshots below:

    Default empty cart:

    Screenshot-from-2022-07-03-11-47-29.png

    Custom empty cart after adding the code snippet: (Media source: link)

    Screenshot-from-2022-07-03-11-48-56.png

    I recommend that you perform this test:

    * Temporarily switch your theme to Storefront
    * Disable all plugins except for WooCommerce
    * Test the cart page again, preferably under incognito mode.

    If you see the custom empty cart image after that, next you should reactivate the theme and plugins one by one, testing after each reactivation, until you find the one that was causing the issue. You can find a more detailed explanation on how to perform this test here.

    Best

    Thread Starter leroy

    (@leroytuttle)

    so your saying to go to another theme storefront undo every plugin and put it in and if it works. You are referring to a plugin that is causing this issue…huh.

    how bout if I do it in my current theme and undo every plug in and put it in, and see if it works, many do say to change your site to default but I dont how to do that.
    however, I will check it out using your directions and see what happens. and do my theme and each plug in one by one. I have time as my site doesnt have much traffic so no biggie.

    I thank you and good day.

    Leroy

    Hello @leroytuttle!

    To rule out all possible conflicts we need you to switch to Storefront OR Twenty Twenty Two theme, disable all plugins except WooCommerce, and remove any custom codes that you may have.
    You can find a more detailed explanation of how to do a conflict test here: https://docs.woocommerce.com/document/how-to-test-for-conflicts/

    Please let us know how it goes.

    Thread Starter leroy

    (@leroytuttle)

    I don’t know how, I changed to store front and unloaded all my plugins, and it didn’t work, sew… I just went back to my original theme and put all my plugins back and it worked. I’ll be back if I have any more issues

    thanks all for the help

    Leroy

    • This reply was modified 3 years, 5 months ago by leroy.
    • This reply was modified 3 years, 5 months ago by leroy.
    Thread Starter leroy

    (@leroytuttle)

    well…it works a little, it was there but if I put something in the cart and take it out it doesn’t work. huh

    I was doing some customization and noticed it was there in the empty cart but when I went out of customization and tried it with a product, and removed product it doesn’t work.

    Thread Starter leroy

    (@leroytuttle)

    and again I lost my colors out of my color swatches 8/

    Hey @leroytuttle,

    I know this is frustrating. Clearly, there is some manner of conflict on the site and the snippet provided above. We’re not in a position to troubleshoot that for you. It could be it’s not added quite correctly, the theme may have a conflict, or it could be something we’re not aware of causing the trouble.

    If you’re not able to track it down, then you’ll want to reach out to a developer and get them to fix this for you. There are freelance developers at Codeable who would be happy to help you out.

    https://woocommerce.com/codeable/

    Take care

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘still searching for empty cart php’ is closed to new replies.