因为这个通知是硬编码在WC_Cartadd_to_cart()方法中的(from line 1075 to 1083):
throw new Exception(
sprintf(
'<a href="%s" class="button wc-forward">%s</a> %s',
wc_get_cart_url(),
__( 'View cart', 'woocommerce' ),
/* translators: 1: quantity in stock 2: current quantity */
sprintf( __( 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), wc_format_stock_quantity_for_display( $product_data->get_stock_quantity(), $product_data ), wc_format_stock_quantity_for_display( $products_qty_in_cart[ $product_data->get_stock_managed_by_id() ], $product_data ) )
)
);
更改url链接的唯一方法是使用woocommerce_get_cart_url过滤钩located inside the function wc_get_cart_url()(在本通知中使用)如下仅适用于单个产品页面:
add_filter( 'woocommerce_get_cart_url', 'filter_get_cart_url' );
function filter_get_cart_url( $url ) {
// Only on single product pages
if( is_product() )
$url = wc_get_checkout_url();
return $url;
}
要将使用wc_get_cart_url() 的所有网址链接更改为结帐网址,您将改用:
add_filter( 'woocommerce_get_cart_url', 'wc_get_checkout_url' );
补充:要使其在除购物车和结帐页面之外的任何地方都能正常工作,请使用以下内容:
add_filter( 'woocommerce_get_cart_url', 'filter_get_cart_url' );
function filter_get_cart_url( $url ) {
// Except on cart and checkout pages
if( ! ( is_cart() || is_checkout() ) )
$url = wc_get_checkout_url();
return $url;
}
代码在您的活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。
相关:Change the "view cart" product overlay button on product loops in Woocommerce