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.
Метод класса: SignupService{}
Хуков нет.
Возвращает
bool. True if the notification matches the posted attributes.
Использование
// private - только в коде основоного (родительского) класса $result = $this->matches_posted_attributes( $notification, $posted_attributes ): bool;
- $notification(Notification) (обязательный)
- The notification.
- $posted_attributes(массив) (обязательный)
- The posted attributes.
Код SignupService::matches_posted_attributes() SignupService::matches posted attributes WC 11.2.2
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;
}