1 回答

TA貢獻1780條經驗 獲得超5個贊
由于此通知是硬編碼在WC_Cart
?add_to_cart()
方法中(從行1075
到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
過濾器掛鉤(在本通知中使用),如下所示,僅適用于單個產品頁面: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;
}
要更改用于結賬 url 的所有 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;
}
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;
}
要更改用于結賬 url 的所有 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;
}
- 1 回答
- 0 關注
- 136 瀏覽
添加回答
舉報