Automattic\WooCommerce\Internal\StockNotifications\Frontend
MyAccountView::get_rows
Flatten notifications into display rows.
Action URLs are empty strings when the action does not apply to the row, so the template only has to test for a non-empty value.
Method of the class: MyAccountView{}
No Hooks.
Returns
array<int,array<string,mixed>>.
Usage
// private - for code of main (parent) class only $result = $this->get_rows( $notifications, $current_page ): array;
- $notifications(array
) (required) - Notifications to flatten.
- $current_page(int) (required)
- 1-indexed page the rows render on, carried by the action URLs.
MyAccountView::get_rows() MyAccountView::get rows code WC 11.2.1
private function get_rows( array $notifications, int $current_page ): array {
$rows = array();
foreach ( $notifications as $notification ) {
if ( ! $notification instanceof Notification ) {
continue;
}
$id = (int) $notification->get_id();
$product_name = MyAccountEndpoint::get_display_product_name( $notification );
$variation = (string) $notification->get_product_formatted_variation_list( true );
$date_created = $notification->get_date_created();
$can_resend = MyAccountEndpoint::can_resend( $notification );
$can_cancel = MyAccountEndpoint::is_cancellable( $notification );
$label_name = '' !== $product_name ? $product_name : __( 'an unavailable product', 'woocommerce' );
if ( '' !== $variation ) {
$label_name .= ' ' . $variation;
}
$rows[] = array(
'id' => $id,
'status' => (string) $notification->get_status(),
'product_name' => $product_name,
'product_url' => (string) $notification->get_product_permalink(),
'variation' => $variation,
'date_iso' => $date_created ? $date_created->date( 'c' ) : '',
'date_display' => $date_created ? \wc_format_datetime( $date_created ) : '',
'resend_url' => $can_resend ? MyAccountEndpoint::get_action_url( MyAccountEndpoint::ACTION_RESEND, $id, $current_page ) : '',
/* translators: %s: product name, followed by its variation attributes when the sign-up is for a variation. */
'resend_label' => $can_resend ? sprintf( __( 'Resend verification email for %s', 'woocommerce' ), $label_name ) : '',
'cancel_url' => $can_cancel ? MyAccountEndpoint::get_action_url( MyAccountEndpoint::ACTION_CANCEL, $id, $current_page ) : '',
/* translators: %s: product name, followed by its variation attributes when the sign-up is for a variation. */
'cancel_label' => $can_cancel ? sprintf( __( 'Cancel stock notification for %s', 'woocommerce' ), $label_name ) : '',
);
}
return $rows;
}