Automattic\WooCommerce\StoreApi\Utilities

LocalPickupUtils::get_local_pickup_method_ids()public staticWC 1.0

Gets a list of payment method ids that support the 'local-pickup' feature.

Method of the class: LocalPickupUtils{}

No Hooks.

Return

String[]. List of payment method ids that support the 'local-pickup' feature.

Usage

$result = LocalPickupUtils::get_local_pickup_method_ids();

LocalPickupUtils::get_local_pickup_method_ids() code WC 9.0.1

public static function get_local_pickup_method_ids() {
	$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()
	);

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