3 回答

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊
購物車頁面
is_cart()
在購物車頁面上返回 true。
結(jié)帳頁面
is_checkout()
在結(jié)帳頁面上返回 true。

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
請注意,is_checkout()如果您提早需要它(我認(rèn)為在加載模板之前),它是無用的,并且如果過早調(diào)用它,它將在結(jié)帳頁面上錯(cuò)誤地返回 false。
這樣的事情更普遍:
/**
* Checks if checkout is the current page.
*
* @return boolean
*/
function better_is_checkout() {
$checkout_path = wp_parse_url(wc_get_checkout_url(), PHP_URL_PATH);
$current_url_path = wp_parse_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", PHP_URL_PATH);
return (
$checkout_path !== null
&& $current_url_path !== null
&& trailingslashit($checkout_path) === trailingslashit($current_url_path)
);
}
is_checkout() 適用于實(shí)際問題,但該問題在“WooCommerce check if checkout”方面在 Google 中也排名第一
這同樣適用于購物車:
/**
* Checks if cart is the current page.
*
* @return boolean
*/
function better_is_cart() {
$cart_path = wp_parse_url(wc_get_cart_url(), PHP_URL_PATH);
$current_url_path = wp_parse_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", PHP_URL_PATH);
return (
$cart_path !== null
&& $current_url_path !== null
&& trailingslashit($cart_path) === trailingslashit($current_url_path)
);
}

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
如果你想使用 wordpress 功能,這里有 `is_page('name')' 供您使用。
您需要使用頁面的名稱(頁面別名)。在示例中,我假設(shè)它們被稱為“購物車”和“結(jié)帳”。
if (!is_page('cart') && !is_page('checkout')) { ... }
您還可以使用 woocommerce 為您提供的條件標(biāo)簽。
如果您遇到 woocommerce 功能問題或想繼續(xù)使用 wordpress 功能,我的回答可能是另一種選擇。
- 3 回答
- 0 關(guān)注
- 189 瀏覽
添加回答
舉報(bào)