Title: Henry I.'s Replies | WordPress.org

---

# Henry I.

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

 *   [Profile](https://wordpress.org/support/users/henrygee/)
 *   [Topics Started](https://wordpress.org/support/users/henrygee/topics/)
 *   [Replies Created](https://wordpress.org/support/users/henrygee/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/henrygee/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/henrygee/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/henrygee/engagements/)
 *   [Favorites](https://wordpress.org/support/users/henrygee/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] Add to Cart button redirecting to homepage](https://wordpress.org/support/topic/add-to-cart-button-redirecting-to-homepage/)
 *  [Henry I.](https://wordpress.org/support/users/henrygee/)
 * (@henrygee)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/add-to-cart-button-redirecting-to-homepage/#post-13379725)
 * [@yazdaniwp](https://wordpress.org/support/users/yazdaniwp/) Pls, can you help.
   I notice when I try adding a product [https://mydomain.com/?add-to-cart=1260](https://mydomain.com/?add-to-cart=1260)
   it gives me this error message saying your cart is empty. This is my code, can
   you direct me on the right one>>>
 *     ```
       add_action( 'init', 'ywp_goto_product_after_add_to_cart' );
       function ywp_goto_product_after_add_to_cart() {
           if ( ! isset ( $_GET['add-to-cart'] ) ) return;
   
           // Remove #
           $product_id = intval( $_GET['add-to-cart'] );
   
           // Check id is a product id
           $product    = wc_get_product( $product_id );
   
           if ( $product ) {
               $url    = get_the_permalink( $product_id );
               wp_safe_redirect( 'cart' );
               exit;
           }
       }
       ```
   
    -  This reply was modified 5 years, 8 months ago by [Henry I.](https://wordpress.org/support/users/henrygee/).
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WooCommerce] Add to Cart button redirecting to homepage](https://wordpress.org/support/topic/add-to-cart-button-redirecting-to-homepage/)
 *  [Henry I.](https://wordpress.org/support/users/henrygee/)
 * (@henrygee)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/add-to-cart-button-redirecting-to-homepage/#post-13379681)
 * [@yazdaniwp](https://wordpress.org/support/users/yazdaniwp/) THANK YOUUUUUUUUU
   SO MUCH. Been worried because these issues have made me lose a lot of sales. 
   Thanks. It worked, I hard to add “checkout” in place of $url because I want them
   redirected to my Checkout Page. Thanks.

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