Automattic\WooCommerce\Internal\PushNotifications\Controllers
NotificationPreferencesRestController::get_args
Get the accepted arguments for the POST request.
Each preference is an object so future sub-fields can be added without a schema-version bump. Keys are derived from the service's defaults so this stays in lock-step with the list of supported notification types.
Method of the class: NotificationPreferencesRestController{}
No Hooks.
Returns
Array
Usage
// private - for code of main (parent) class only $result = $this->get_args(): array;
NotificationPreferencesRestController::get_args() NotificationPreferencesRestController::get args code WC 10.9.1
private function get_args(): array {
$args = array();
$defaults = $this->preferences_service->get_defaults();
foreach ( $defaults as $key => $shape ) {
$properties = array(
'enabled' => array(
'type' => 'boolean',
'description' => __( 'Whether this notification type is enabled.', 'woocommerce' ),
),
);
if ( array_key_exists( 'min_amount', $shape ) ) {
$properties['min_amount'] = array(
'type' => array( 'number', 'null' ),
'minimum' => 0,
'exclusiveMinimum' => true,
'description' => __( 'Minimum order amount required to trigger this notification, or null to disable the threshold.', 'woocommerce' ),
);
}
if ( array_key_exists( 'max_rating', $shape ) ) {
$properties['max_rating'] = array(
'type' => array( 'integer', 'null' ),
'minimum' => 1,
'maximum' => 5,
'description' => __( 'Maximum star rating that triggers a review notification (1–5), or null to disable the threshold.', 'woocommerce' ),
);
}
$boolean_sub_fields = array( 'low_stock', 'out_of_stock', 'on_backorder' );
foreach ( $boolean_sub_fields as $sub_field ) {
if ( array_key_exists( $sub_field, $shape ) ) {
$properties[ $sub_field ] = array(
'type' => 'boolean',
'description' => sprintf(
/* translators: %s: sub-field name (e.g. low_stock). */
__( 'Whether %s notifications are enabled for this type.', 'woocommerce' ),
$sub_field
),
);
}
}
$args[ $key ] = array(
'description' => sprintf(
/* translators: %s: notification preference key (e.g. store_order). */
__( 'Preferences for the %s push notification type.', 'woocommerce' ),
$key
),
'type' => 'object',
'properties' => $properties,
'required' => false,
'validate_callback' => 'rest_validate_request_arg',
);
}//end foreach
return $args;
}