$this->label(),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
/* translators: %s: order count */
'label_count' => _n_noop(
'پیک موتوری (%s)',
'پیک موتوری (%s)',
'rahkar-toolkit'
),
]
);
}
/**
* The human label.
*/
public function label(): string {
return __( 'پیک موتوری', 'rahkar-toolkit' );
}
/**
* Slot the status into WooCommerce's status dropdown.
*
* Placed straight after «در حال انجام», which is the step it follows in the
* fulfilment flow. If WooCommerce ever drops or renames `wc-processing` the
* entry is appended instead, so the status can never go silently missing
* from the dropdown that is the only way to set it by hand.
*
* @param array $statuses Existing statuses.
*
* @return array
*
* @internal Hooked callback.
*/
public function addToDropdown( $statuses ): array {
$out = [];
foreach ( (array) $statuses as $key => $label ) {
$out[ $key ] = $label;
if ( 'wc-processing' === $key ) {
$out[ self::POST_STATUS ] = $this->label();
}
}
if ( ! isset( $out[ self::POST_STATUS ] ) ) {
$out[ self::POST_STATUS ] = $this->label();
}
return $out;
}
/**
* Add the bulk action to the orders list.
*
* Only the menu item is added. WooCommerce's order list table already
* handles any `mark_` bulk action generically once `wc-` is
* a registered order status, so it performs the status change, the nonce
* check and the "X orders updated" notice.
*
* @param array $actions Existing bulk actions.
*
* @return array
*
* @internal Hooked callback.
*/
public function addBulkAction( $actions ): array {
$label = __( 'تغییر وضعیت به پیک موتوری', 'rahkar-toolkit' );
$key = 'mark_' . self::SLUG;
$out = [];
foreach ( (array) $actions as $action => $text ) {
$out[ $action ] = $text;
if ( 'mark_processing' === $action ) {
$out[ $key ] = $label;
}
}
if ( ! isset( $out[ $key ] ) ) {
$out[ $key ] = $label;
}
return $out;
}
/**
* Colour the status badge on the order screens.
*
* WooCommerce renders each status as ``.
* Unstyled, a custom status falls back to the grey default and is hard to
* pick out of a long list. The violet is deliberate: not the brand blue,
* which reads as "completed", and not a red, which reads as an error or a
* cancellation.
*
* Admin chrome only, and only on the screens where the badge can appear, so
* an inline style beats registering a stylesheet that every other admin page
* would have to skip.
*
* @internal Hooked callback.
*/
public function badgeStyle(): void {
if ( ! $this->onOrderScreen() ) {
return;
}
InlineStyle::print(
'rahkar-courier-status',
sprintf(
'.order-status.status-%1$s{background:#ede9fe;color:#5b21b6}.order-status.status-%1$s::before{background:#7c3aed}',
sanitize_html_class( self::SLUG )
)
);
}
/**
* Is the current admin screen one where an order status badge is rendered?
*
* Covers HPOS and the legacy post-table screens, plus the dashboard, where
* WooCommerce's status widget can surface the badge.
*/
private function onOrderScreen(): bool {
if ( ! function_exists( 'get_current_screen' ) ) {
return false;
}
$screen = get_current_screen();
if ( ! $screen ) {
return false;
}
return str_contains( $screen->id, 'wc-orders' )
|| in_array( $screen->id, [ 'edit-shop_order', 'shop_order', 'dashboard' ], true );
}
}