My Courses > CustomizeWoo > Module 4 > Lesson 07: Cart Page: ADD Content

Cart Page: ADD Content

MARK LESSON AS COMPLETE

This is how to add content to the cart page by using the visual hook guide. Always start from displaying some simple “TEXT” in the correct position, and then make your functions more complex. A little win is better than hours spent troubleshooting.

Video

Please note: English captions are enabled by default (click on “CC” in the video player to disable). Also, you can click on the “gear” icon to manage quality and playback speed. Enjoy!

Sorry, this video is visible to logged in and fully registered students only.
If you already enrolled in this course, please LOG IN
Otherwise, please enroll in the FREE / PRO COURSE
For any other queries, feel free to get in touch

Useful Links

WooCommerce Visual Hook Guide: Cart Page

Related Snippets

WooCommerce: Add Content to Empty Cart Page

WooCommerce: Display Categories Under Product Name @ Cart

WooCommerce: Display Weight @ Cart & Checkout

WooCommerce: “You Only Need $$$ to Get Free Shipping!” @ Cart

6 thoughts on “Cart Page: ADD Content

  1. Hello Rodolfo,
    How could we change “Proceed to checkout” button text on the cart, based on the product category? Let’s suppose there is only a product category on the cart, not more. Is it possible?
    Thank you!

    1. Of course, but you should watch https://www.businessbloomer.com/lesson/cuwm5l05/ (so you can find the correct “filter” and not an “action” in this case) and then https://www.businessbloomer.com/lesson/cuwm5l02/ (so you can apply “conditional logic”). Let me know how it goes!

      1. Hello Rodolfo,

        I was able to change the “Proceed to checkout” button text (and other strings) on the cart page for a specific product category. But I was not able to imagine where to insert conditionals if another product category is in the cart.
        Here is the code snippet I used:

        /**
         * @snippet       Check if Product Category is in the Cart and translate to different languages - WooCommerce
         */
         
        add_action('woocommerce_before_cart', 'bbb_check_category_in_cart');
         
        function bbb_check_category_in_cart() {
         
        // Set $cat_in_cart to false
        $cat_in_cart = false;
         
        // Loop through all products in the Cart        
        foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
         
            // If Cart has category "music", set $cat_in_cart to true
            if ( has_term( 'music', 'product_cat', $cart_item['product_id'] ) ) {
                $cat_in_cart = true;
                break;
            }
        	
        }
           
        // Translate to Spanish Language if the product category "music" is in the Cart      
        if ( $cat_in_cart ) {
         
        add_filter( 'gettext', 'bbb_translate_woocommerce_strings', 999, 3 );
          
        function bbb_translate_woocommerce_strings( $translated, $untranslated, $domain ) {
         
           if ( ! is_admin() && 'woocommerce' === $domain ) {
         
              switch ( $untranslated) {
         
                 case 'Proceed to checkout' :
         
                    $translated = 'Proceder a la compra!';
                    break;
         
                 case 'Product' :
         
                    $translated = 'Producto';
                    break;
        			
        		case 'Price' :
         
                   $translated = 'Precio';
                   break;
        		   
        		case 'Quantity' :
         
                   $translated = 'Cantidad';
                   break;
        		   
        		case 'Subtotal' :
         
                   $translated = 'Total parcial';
                   break;
        		   
              }
         
           }   
          
           return $translated;
         
        }
        
         
        }
         
        }

        Please give me a hint where should I include in the function above the conditional for the product category “albums”. Where should I add:

        // If Cart has category "albums", set $cat_in_cart to true
            if ( has_term( 'albums', 'product_cat', $cart_item['product_id'] ) ) {
                $cat_in_cart = true;
                break;
            }

        and where should I add filter ‘gettext’ for the product category “albums”?
        Tried a lot, but with no success. Please advice.

        1. Ok Marcel, let’s see if I can help. First of all, use “elseif” and redefine $cat_in_cart because you have 2 categories now:

          if ( has_term( 'music', 'product_cat', $cart_item['product_id'] ) ) {
             $music_in_cart = true;
             break;
          } elseif ( has_term( 'albums', 'product_cat', $cart_item['product_id'] ) ) {
             $albums_in_cart = true;
             break;
          }
          

          Second, take the function bbb_translate_woocommerce_strings() out of the nesting, and leave it on its own. Now you will need two of them:

          function bbb_translate_woocommerce_strings_music() {
             // bla
          }
          function bbb_translate_woocommerce_strings_albums() {
             // bla bla
          }
          

          All it’s left now is to call the right filters, so you’d do this in the existing function:

          if ( $music_in_cart ) {
             add_filter( 'gettext', 'bbb_translate_woocommerce_strings_music', 999, 3 );
          } elseif ( $albums_in_cart ) {
             add_filter( 'gettext', 'bbb_translate_woocommerce_strings_malbums', 999, 3 );
          }
          

          Does this help?

          1. Hello Rodolfo,
            Thank you very much. Until now, all worked as expected, except the fact I had to use this code:

            function bbb_translate_woocommerce_strings_albums($translated, $untranslated, $domain){
               // bla
            }

            instead of

            function bbb_translate_woocommerce_strings_music() {
               // bla
            }

            Without “$translated, $untranslated, $domain” between brackets, the cart shows empty fields. I will dig more, to find why. Anyway, thank you very much!

            1. Sorry yes you definitely need to use those 3 parameters

Questions? Feedback? Support? Leave your comment now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]

Your email address will not be published. Required fields are marked *