Checkout::handle_request( string $cart_id, BigCommerceApiv3ApiCartApi $cart_api )
Summary
No summary available.Parameters
- $cart_id
-
(string) (Required)
- $cart_api
-
(BigCommerceApiv3ApiCartApi) (Required)
Return
(void)
Source
File: src/BigCommerce/Cart/Checkout.php
public function handle_request( $cart_id, CartApi $cart_api ) { if ( empty( $cart_id ) ) { $error = new \WP_Error( 'checkout', __( 'Please add some items to your cart before checking out.', 'bigcommerce' ) ); do_action( 'bigcommerce/form/error', $error, $_POST, home_url( '/' ) ); return; } if ( get_option( Cart_Settings::OPTION_EMBEDDED_CHECKOUT, true ) ) { $checkout_page = get_option( Checkout_Page::NAME, 0 ); if ( $checkout_page ) { wp_safe_redirect( get_permalink( $checkout_page ), 303 ); exit(); } } try { $redirects = $cart_api->cartsCartIdRedirectUrlsPost( $cart_id )->getData(); $checkout_url = $redirects[ 'checkout_url' ]; /** * This filter is documented in src/BigCommerce/Cart/Cart.php */ $checkout_url = apply_filters( 'bigcommerce/checkout/url', $checkout_url ); wp_redirect( $checkout_url, 303 ); exit(); } catch ( \Exception $e ) { $error = new \WP_Error( 'api_error', __( "We're having some difficulty redirecting you to checkout. Please try again.", 'bigcommerce' ) ); do_action( 'bigcommerce/form/error', $error, $_POST, home_url( '/' ) ); return; } }