Skip to content

Commit 47e5565

Browse files
senadiropr
authored andcommitted
Introduce Additional Fields API for Checkout Block woocommerce/woocommerce-blocks#12073
1 parent 08349bc commit 47e5565

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CheckoutFields {
2222
*
2323
* @var array
2424
*/
25-
private $additional_fields = array();
25+
private $additional_fields = [];
2626

2727
/**
2828
* Fields locations.
@@ -36,7 +36,7 @@ class CheckoutFields {
3636
*
3737
* @var array
3838
*/
39-
private $supported_field_types = array( 'text', 'select' );
39+
private $supported_field_types = [ 'text', 'select', 'checkbox' ];
4040

4141
/**
4242
* Instance of the asset data registry.
@@ -690,16 +690,16 @@ private function get_field_from_object( $key, $object, $group = '' ) {
690690
*/
691691
public function get_all_fields_from_customer( $customer, $all = false ) {
692692
$customer_id = $customer->get_id();
693-
$meta_data = array(
694-
'billing' => array(),
695-
'shipping' => array(),
696-
'additional' => array(),
697-
);
693+
$meta_data = [
694+
'billing' => [],
695+
'shipping' => [],
696+
'additional' => [],
697+
];
698698
if ( ! $customer_id ) {
699699
if ( isset( wc()->session ) ) {
700-
$meta_data['billing'] = wc()->session->get( self::BILLING_FIELDS_KEY, array() );
701-
$meta_data['shipping'] = wc()->session->get( self::SHIPPING_FIELDS_KEY, array() );
702-
$meta_data['additional'] = wc()->session->get( self::ADDITIONAL_FIELDS_KEY, array() );
700+
$meta_data['billing'] = wc()->session->get( self::BILLING_FIELDS_KEY, [] );
701+
$meta_data['shipping'] = wc()->session->get( self::SHIPPING_FIELDS_KEY, [] );
702+
$meta_data['additional'] = wc()->session->get( self::ADDITIONAL_FIELDS_KEY, [] );
703703
}
704704
} else {
705705
$meta_data['billing'] = get_user_meta( $customer_id, self::BILLING_FIELDS_KEY, true );
@@ -719,11 +719,11 @@ public function get_all_fields_from_customer( $customer, $all = false ) {
719719
* @return array An array of fields.
720720
*/
721721
public function get_all_fields_from_order( $order, $all = false ) {
722-
$meta_data = array(
723-
'billing' => array(),
724-
'shipping' => array(),
725-
'additional' => array(),
726-
);
722+
$meta_data = [
723+
'billing' => [],
724+
'shipping' => [],
725+
'additional' => [],
726+
];
727727
if ( $order instanceof \WC_Order ) {
728728
$meta_data['billing'] = $order->get_meta( self::BILLING_FIELDS_KEY, true );
729729
$meta_data['shipping'] = $order->get_meta( self::SHIPPING_FIELDS_KEY, true );
@@ -741,9 +741,9 @@ public function get_all_fields_from_order( $order, $all = false ) {
741741
* @return array An array of fields.
742742
*/
743743
private function format_meta_data( $meta, $all = false ) {
744-
$billing_fields = $meta['billing'] ?? array();
745-
$shipping_fields = $meta['shipping'] ?? array();
746-
$additional_fields = $meta['additional'] ?? array();
744+
$billing_fields = $meta['billing'] ?? [];
745+
$shipping_fields = $meta['shipping'] ?? [];
746+
$additional_fields = $meta['additional'] ?? [];
747747

748748
$fields = array();
749749

plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Cart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ public function test_add_variable_product_to_cart_returns_variation_data() {
603603
array(
604604
'variation' => array( // order matters, alphabetical attribute order.
605605
array(
606-
'attribute' => 'color',
606+
'attribute' => 'Color',
607607
'value' => 'red',
608608
),
609609
array(

0 commit comments

Comments
 (0)