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

Commit

Permalink
Use array_reduce and update comments in get_local_pickup_method_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
opr committed Feb 3, 2023
1 parent 2fcb7d1 commit a495999
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/Shipping/ShippingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,24 @@ function() {
* @return string[] List of payment method ids that support the 'local_pickup' feature.
*/
public function get_local_pickup_method_ids() {
$methods_supporting_local_pickup = array_unique(
array_map(
function( $method ) {
return $method->id;
},
array_filter(
WC()->shipping()->get_shipping_methods(),
function( $method ) {
return $method->supports( 'local_pickup' );
},
true
)
)
$all_methods_supporting_local_pickup = array_reduce(
WC()->shipping()->get_shipping_methods(),
function( $methods, $method ) {
if ( $method->supports( 'local_pickup' ) ) {
$methods[] = $method->id;
}
return $methods;
},
array()
);

return array_values( $methods_supporting_local_pickup );
// This array_unique is necessary because WC()->shipping()->get_shipping_methods() can return duplicates.
return array_unique(
// We use array_values because this will be used in JS, so we don't need the (numerical) keys.
array_values(
$all_methods_supporting_local_pickup
)
);
}

/**
Expand Down

0 comments on commit a495999

Please sign in to comment.