__('Discount Code', 'wp-ultimo'), // singular name of the listed records 'plural' => __('Discount Codes', 'wp-ultimo'), // plural name of the listed records 'ajax' => true, // does this table support ajax? 'add_new' => array( 'url' => wu_network_admin_url('wp-ultimo-edit-discount-code'), 'classes' => '', ), ) ); } /** * Displays the content of the name column. * * @since 2.0.0 * * @param WP_Ultimo\Models\Discount_Code $item Discount_Code object. */ public function column_name($item): string { $url_atts = array( 'id' => $item->get_id(), 'model' => 'discount_code', ); $title = sprintf('%s', wu_network_admin_url('wp-ultimo-edit-discount-code', $url_atts), $item->get_name()); $actions = array( 'edit' => sprintf('%s', wu_network_admin_url('wp-ultimo-edit-discount-code', $url_atts), __('Edit', 'wp-ultimo')), 'delete' => sprintf( '%s', __('Delete', 'wp-ultimo'), wu_get_form_url( 'delete_modal', $url_atts ), __('Delete', 'wp-ultimo') ), ); return $title . $this->row_actions($actions); } /** * Displays the content of the value column. * * @since 2.0.0 * * @param WP_Ultimo\Models\Discount_Code $item Discount_Code object. * * @return string */ public function column_value($item) { if ( ! $item->get_value()) { return __('No Discount', 'wp-ultimo'); } $value = wu_format_currency($item->get_value()); if ($item->get_type() === 'percentage') { $value = number_format($item->get_value(), 0) . '%'; } // translators: placeholder is the amount of discount. e.g. 10% or $5. return sprintf(__('%s OFF', 'wp-ultimo'), $value); } /** * Displays the content of the setup fee value column. * * @since 2.0.0 * * @param WP_Ultimo\Models\Discount_Code $item Discount_Code object. * * @return string */ public function column_setup_fee_value($item) { if ( ! $item->get_setup_fee_value()) { return __('No Discount', 'wp-ultimo'); } $value = wu_format_currency($item->get_setup_fee_value()); if ($item->get_setup_fee_type() === 'percentage') { $value = number_format($item->get_setup_fee_value()) . '%'; } // translators: placeholder is the amount of discount. e.g. 10% or $5. return sprintf(__('%s OFF', 'wp-ultimo'), $value); } /** * Displays the use limitations. * * @since 2.0.0 * * @param WP_Ultimo\Models\Discount_Code $item Discount_Code object. * @return string */ public function column_uses($item) { // translators: the placeholder is the number of times this coupon was used. $html = sprintf(__('Used %d time(s)', 'wp-ultimo'), $item->get_uses()); if ($item->get_max_uses() > 0) { // translators: the placeholder is the number of times this coupon can be used before becoming inactive. $html .= '' . sprintf(__('Allowed uses: %d', 'wp-ultimo'), $item->get_max_uses()) . ''; } else { $html .= '' . __('No Limits', 'wp-ultimo') . ''; } return $html; } /** * Shows the code as a tag. * * @since 2.0.0 * * @param WP_Ultimo\Models\Discount_Code $item Discount_Code object. * @return string */ public function column_coupon_code($item) { $code = $item->get_code(); $html = '' . strtoupper((string) $code) . ''; $valid = $item->is_valid(); if (is_wp_error($valid)) { $html .= sprintf('%s', wu_tooltip_text($valid->get_error_message()), __('Inactive', 'wp-ultimo')); } return $html; } /** * Returns the list of columns for this particular List Table. * * @since 2.0.0 * @return array */ public function get_columns() { $columns = array( 'cb' => '', 'name' => __('Name', 'wp-ultimo'), 'coupon_code' => __('Code', 'wp-ultimo'), 'uses' => __('Uses', 'wp-ultimo'), 'value' => __('Value', 'wp-ultimo'), 'setup_fee_value' => __('Setup Fee Value', 'wp-ultimo'), 'date_expiration' => __('Dates', 'wp-ultimo'), ); return $columns; } /** * Returns the filters for this page. * * @since 2.0.0 */ public function get_filters(): array { return array( 'filters' => array(), 'date_filters' => array(), ); } }