1 回答

TA貢獻1856條經驗 獲得超5個贊
我使用以下代碼解決了這個問題:
add_filter( 'woocommerce_is_rest_api_request', [ $this, 'simulate_as_not_rest' ] );
/**
* We have to tell WC that this should not be handled as a REST request.
* Otherwise we can't use the product loop template contents properly.
* Since WooCommerce 3.6
*
* @param bool $is_rest_api_request
* @return bool
*/
public function simulate_as_not_rest( $is_rest_api_request ) {
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
return $is_rest_api_request;
}
// Bail early if this is not our request.
if ( false === strpos( $_SERVER['REQUEST_URI'], $this->namespace ) ) {
return $is_rest_api_request;
}
return false;
}
我將命名空間設置為等于 API 路由的命名空間。
我希望這可以幫助別人
- 1 回答
- 0 關注
- 226 瀏覽
添加回答
舉報