Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

change URL for woocommerce cart icon in nav menu to checkout (instead of cart)

  • Hi GenerateSupport,

    May you please share function snippet to change icon URL?

    Right now it goes to http://10.0.0.103:8261/cart/ but I desire “checkout” instead like ⟶ http://10.0.0.103:8261/CHECKOUT/

    https://i.imgur.com/Q4l7hUw.png

  • Hi there,

    Can you try this?

    add_filter( 'woocommerce_get_cart_url', 'tu_custom_cart_url' );
    function tu_custom_cart_url() {
        return 'URL TO YOUR CHECKOUT';
    }
  • Thanks!!

    This is great.

  • You are welcome   🙂

  • If anyone else needs, here is working version

    add_action( 'template_redirect', function() {
        // Don't redirect if coming from checkout
        $referer = wp_get_referer();
        $is_from_checkout = $referer && strpos( $referer, 'checkout' ) !== false;
        
        if ( is_cart() && ! $is_from_checkout ) {
            if ( WC()->cart->is_empty() ) {
                wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
                exit();
            } else {
                wp_safe_redirect( 'http://10.0.0.103:8261/checkout/' );
                exit();
            }
        }
    });

    * Cart is empty + cart icon clicked → Redirect to shop
    * Cart has items + cart icon clicked → Redirect to checkout
    * “Return to cart” clicked from checkout → Shows the cart page normally (no redirect loop)

  • Thanks for sharing your solution 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.