Automattic\WooCommerce\Internal\StockNotifications\Frontend
SignupService::matches_posted_attributes
Check whether a notification was signed up for with the posted attributes.
A variation with "any" attributes can be signed up for more than once with different attribute values, so the stored attributes have to match the posted ones. An empty set of posted attributes matches any notification.
Method of the class: SignupService{}
No Hooks.
Returns
bool. True if the notification matches the posted attributes.
Usage
// private - for code of main (parent) class only $result = $this->matches_posted_attributes( $notification, $posted_attributes ): bool;
- $notification(Notification) (required)
- The notification.
- $posted_attributes(array) (required)
- The posted attributes.
SignupService::matches_posted_attributes() SignupService::matches posted attributes code WC 11.2.1
private function matches_posted_attributes( Notification $notification, array $posted_attributes ): bool {
if ( empty( $posted_attributes ) ) {
return true;
}
$stored_attributes = $notification->get_meta( 'posted_attributes' );
if ( ! is_array( $stored_attributes ) || count( $stored_attributes ) !== count( $posted_attributes ) ) {
return false;
}
foreach ( $posted_attributes as $key => $value ) {
if ( ! array_key_exists( $key, $stored_attributes ) || (string) $stored_attributes[ $key ] !== (string) $value ) {
return false;
}
}
return true;
}