Shipping_Controller::get_zone_methods( WP_REST_Request $request )
Summary
No summary available.Parameters
- $request
-
(WP_REST_Request) (Required) Full details about the request.
Return
(WP_REST_Response|WP_Error) Response object on success, or WP_Error object on failure.
Source
File: src/BigCommerce/Rest/Shipping_Controller.php
public function get_zone_methods( $request ) { $attributes = $request->get_params(); $cart = $this->get_cart(); $methods = $this->shipping_api->get_shipping_methods( $attributes['zone_id'] ); $methods = array_filter( array_map( function ( $method ) use ( $cart ) { $rate_raw = $this->get_method_rate( $method, $cart ); if ( ! $method->enabled ) { return; } $method_name = $method->name; if ( $method->type === self::SHIPPING_METHOD_TYPE_FREE && $rate_raw > 0 ) { $method_name = __( 'Fixed Shipping', 'bigcommerce' ); } $method = [ 'id' => $method->id, 'name' => $method_name, 'type' => $method->type, 'rate_raw' => $rate_raw, 'rate' => $this->format_price( $rate_raw ), 'fixed_surcharge' => isset( $method->handling_fees->fixed_surcharge ) ? $method->handling_fees->fixed_surcharge : 0, ]; $cart_subtotal = $this->cart_subtotal_for_method( $method, $cart ); $method['cart_subtotal_raw'] = $cart_subtotal; $method['cart_subtotal'] = $this->format_price( $cart_subtotal ); $cart_total = $this->cart_total_for_method( $cart_subtotal, $cart ); $method['cart_total_raw'] = $cart_total; $method['cart_total'] = $this->format_price( $cart_total ); return $method; }, $methods ) ); $controller = Shipping_Methods::factory( [ Shipping_Methods::METHODS => $methods, ] ); $output = $controller->render(); $response = rest_ensure_response( [ 'rendered' => $output, ] ); return $response; }