Automattic\WooCommerce\StoreApi

Authentication::opt_in_checkout_endpoint()publicWC 1.0

Opt in to rate limiting for the checkout endpoint.

Метод класса: Authentication{}

Хуков нет.

Возвращает

\WP_Error|null|true|false.

Использование

$Authentication = new Authentication();
$Authentication->opt_in_checkout_endpoint( $result );
$result(\WP_Error|разное) (обязательный)
Error from another authentication handler, null if we should handle it, or another value if not.

Код Authentication::opt_in_checkout_endpoint() WC 9.6.1

public function opt_in_checkout_endpoint( $result ) {
	if (
		FeaturesUtil::feature_is_enabled( 'rate_limit_checkout' )
		&& $this->is_request_to_store_api()
		&& preg_match( '#/wc/store(?:/v\d+)?/checkout#', $GLOBALS['wp']->query_vars['rest_route'] )
		&& isset( $_SERVER['REQUEST_METHOD'] )
		&& 'POST' === $_SERVER['REQUEST_METHOD']
	) {
		add_filter(
			'woocommerce_store_api_rate_limit_options',
			function ( $options ) {
				$options['enabled'] = true;
				$options['limit']   = 3;
				$options['seconds'] = 60;
				return $options;
			},
			1,
			1
		);
	}
	return $result;
}