Title: Milos Petkovic's Replies | WordPress.org

---

# Milos Petkovic

  [  ](https://wordpress.org/support/users/mpetkovic/)

 *   [Profile](https://wordpress.org/support/users/mpetkovic/)
 *   [Topics Started](https://wordpress.org/support/users/mpetkovic/topics/)
 *   [Replies Created](https://wordpress.org/support/users/mpetkovic/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/mpetkovic/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/mpetkovic/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/mpetkovic/engagements/)
 *   [Favorites](https://wordpress.org/support/users/mpetkovic/favorites/)

 Search replies:

## Forum Replies Created

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

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WooCommerce - Gift Cards] Plugin breaking scripts on site](https://wordpress.org/support/topic/plugin-breaking-scripts-on-site/)
 *  [Milos Petkovic](https://wordpress.org/support/users/mpetkovic/)
 * (@mpetkovic)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/plugin-breaking-scripts-on-site/#post-9954341)
 * Hello there.
 * Basically, fix would look like this:
 *     ```
       ...
       $has_giftcard = "no";
   
       // Check if cart is empty before going through the loop.
       if ( empty( WC()->cart ) ) {
            return $enabled;
       }
   
       foreach ( WC()->cart->get_cart() as $key => $product ) {
       ...
       ```
   
 * Hope this helps.
 * Milos
    -  This reply was modified 8 years, 3 months ago by [Milos Petkovic](https://wordpress.org/support/users/mpetkovic/).
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WooCommerce - Gift Cards] Plugin breaking scripts on site](https://wordpress.org/support/topic/plugin-breaking-scripts-on-site/)
 *  [Milos Petkovic](https://wordpress.org/support/users/mpetkovic/)
 * (@mpetkovic)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/plugin-breaking-scripts-on-site/#post-9952392)
 * Hello guys,
 * I think I found the source of the problems.
 * Inside the script {plugin}/includes/functions.php on line 84
    seams that WC()-
   >cart object still don’t exists and it’s null which cause the fatal error and
   not loading the rest of the site content.
 * Quick fix would be just to check if WC()->cart is empty before going trough foreach
   loop.
 * Hope you can look into this before next update.
 * Cheers.

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