Dawid Loranc
Dawid Loranc

Reputation: 892

How to change url in "View Cart" button in Woocommerce?

How to change url in "View Cart" button in Woocommerce which shows after clicking "Add to cart" button? I have default http://myshop.com/checkout and I want to change url to custom page (with my cart view combined with checkout): http://myshop.com/custom-page

I know that I should change js behavior, but how?

Upvotes: 1

Views: 11421

Answers (4)

Dnyanesh
Dnyanesh

Reputation: 119

function change_view_cart_link( $params, $handle )
{

          switch ($handle) {

                case 'wc-add-to-cart':
                    $params['cart_url'] = "http://myshop.com/custom-page";
                break;
            }
            return $params;
}
add_filter( 'woocommerce_get_script_data', 'change_view_cart_link',10,2 );

Upvotes: 0

victor
victor

Reputation: 1

go to wp-content\plugins\woocommerce\includes\wc-template-functions.php

then edit raw 1429

function woocommerce_widget_shopping_cart_button_view_cart() {
        echo '<a href="' . esc_url( wc_get_cart_url() ) . '" class="button wc-forward">' . esc_html__( 'View cart', 'woocommerce' ) . '</a>';
}
function woocommerce_widget_shopping_cart_button_view_cart() {
        echo '<a href="' . esc_url( wc_get_cart_url() ) . '" class="button wc-forward">' . esc_html__( 'your text', 'woocommerce' ) . '</a>';
}

version woocommerce 3.0.3strong text

Upvotes: -4

Terri
Terri

Reputation: 352

This filter works for languages. Polylang and Loco handle the UI display string for the button and this function handles the url.

$currentlanguage = get_bloginfo('language');

add_filter('woocommerce_get_checkout_url', 'my_checkout');

function my_checkout($url) {
    global $woocommerce;
     if($currentlanguage = "zh-CN"){
        return $checkout_url = 'http://example.com/zh/chinese_checkout/';
        }
     if ($currentlanguage = "en-US"){
        return $checkout_url = 'http://example.com/en/english_checkout/';
        }
    };  

Upvotes: 2

helgatheviking
helgatheviking

Reputation: 26319

You can filter the checkout url via woocommerce_get_checkout_url

function so_37863005_checkout_url( $url ){

    // Force SSL if needed
    $scheme = ( is_ssl() || 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) ) ? 'https' : 'http';
    $url = site_url( '/custom-page/', $scheme );

    return $url;
}
add_filter( 'woocommerce_get_checkout_url', 'so_37863005_checkout_url', 10, 2 );

Upvotes: 4

Related Questions