Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

[POC] Add fields schema in cart store API #8891

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/StoreApi/Schemas/V1/CartSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,27 @@ public function get_item_response( $cart ) {
// Get visible cross sells products.
$cross_sells = array_filter( array_map( 'wc_get_product', $cart->get_cross_sells() ), 'wc_products_array_filter_visible' );

$wc_checkout = \WC_Checkout::instance();
$checkout_fields = $wc_checkout->get_checkout_fields();

$fields = array();
foreach ( $checkout_fields as $area_id => $area ) {
foreach ( $area as $field_id => $field ) {
if ( $field['custom'] && $field['enabled'] ) {
$fields[ $area_id ][] = array(
'id' => $field_id,
'label' => $field['label'],
'required' => $field['required'],
'type' => $field['type'],
'validate' => $field['validate'],
'priority' => $field['priority'],
);
}
}
}

return [
'fields' => $fields,
'coupons' => $this->get_item_responses_from_schema( $this->coupon_schema, $cart->get_applied_coupons() ),
'shipping_rates' => $this->get_item_responses_from_schema( $this->shipping_rate_schema, $shipping_packages ),
'shipping_address' => $this->shipping_address_schema->get_item_response( wc()->customer ),
Expand Down