如何在Woocommerce的“查看购物车”按钮中更改网址?

时间:2016-06-16 15:08:40

标签: woocommerce

如何在点击“添加到购物车”按钮后显示的Woocommerce中的“查看购物车”按钮中更改网址?我有默认http://myshop.com/checkout,我想将网址更改为自定义页面(我的购物车视图与结帐一起):http://myshop.com/custom-page

我知道我应该改变js的行为,但是怎么做?

4 个答案:

答案 0 :(得分:4)

您可以通过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 );

答案 1 :(得分:2)

此过滤器适用于语言。 Polylang和Loco处理按钮的UI显示字符串,此函数处理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/';
        }
    };  

答案 2 :(得分:0)

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 );

答案 3 :(得分:-4)

转到wp-content\plugins\woocommerce\includes\wc-template-functions.php

然后编辑原始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>';
}

版本woocommerce 3.0.3 强文