'refund-item', 'plural' => 'refund-items', 'ajax' => false, ) ); $this->get_counts(); } /** * Get the base URL for the order item list table. * * @since 3.0 * * @return string Base URL. */ public function get_base_url() {} /** * Retrieve the view types. * * @since 3.0 * * @return array $views All the views available. */ public function get_views() { return array(); } /** * Retrieve the table columns. * * @since 3.0 * * @return array $columns Array of all the list table columns. */ public function get_columns() { $columns = array( 'cb' => '', 'name' => __( 'Product', 'easy-digital-downloads' ), 'amount' => __( 'Unit Price', 'easy-digital-downloads' ), 'quantity' => __( 'Quantity', 'easy-digital-downloads' ), 'subtotal' => __( 'Subtotal', 'easy-digital-downloads' ), ); // Maybe add tax column. $order = $this->get_order(); if ( $order && $order->get_tax_rate() ) { $columns['tax'] = __( 'Tax', 'easy-digital-downloads' ); } // Total at the end. $columns['total'] = __( 'Total', 'easy-digital-downloads' ); // Return columns. return $columns; } /** * Retrieve the sortable columns. * * @since 3.0 * * @return array Array of all the sortable columns. */ public function get_sortable_columns() { return array(); } /** * Gets the name of the primary column. * * @since 2.5 * @access protected * * @return string Name of the primary column. */ protected function get_primary_column_name() { return 'name'; } /** * Generates a unique ID for an item, to be used as HTML IDs. * We cannot simply use `$item->id` because it's possible that an order item and order adjustment * could have the same ID. * * @param Order_Item|Order_Adjustment $item * * @since 3.0 * @return string */ private function get_item_unique_id( $item ) { return $item instanceof Order_Item ? 'order-item-' . $item->id : 'order-adjustment-' . $item->id; } /** * Returns a string that designates the type of object. This is used in HTML `name` attributes. * * @param Order_Item|Order_Adjustment $item * * @since 3.0 * @return string */ private function get_object_type( $item ) { return $item instanceof Order_Item ? 'order_item' : 'order_adjustment'; } /** * Returns the item display name. * * @param Order_Item|Order_Adjustment $item * * @since 3.0 * @return string */ private function get_item_display_name( $item ) { $name = ''; if ( $item instanceof Order_Item ) { return $item->get_order_item_name(); } if ( $item instanceof Order_Adjustment ) { $name = __( 'Order Fee', 'easy-digital-downloads' ); if ( 'credit' === $item->type ) { $name = __( 'Order Credit', 'easy-digital-downloads' ); } if ( ! empty( $item->description ) ) { $name .= ': ' . $item->description; } } return $name; } /** * This function renders most of the columns in the list table. * * @since 3.0 * * @param Order_Item|Order_Adjustment $item Order item or adjustment object. * @param string $column_name The name of the column. * * @return string Column name. */ public function column_default( $item, $column_name ) { $object_type = $this->get_object_type( $item ); $item_id = $this->get_item_unique_id( $item ); switch ( $column_name ) { case 'amount': return $this->format_currency( $item, $column_name ); case 'total': return $this->format_currency( $item, $column_name, 0 ); case 'quantity': return $this->get_quantity_column( $item, $column_name, $item_id, $object_type ); case 'subtotal': case 'tax': return $this->get_adjustable_column( $item, $column_name, $item_id, $object_type ); default: return property_exists( $item, $column_name ) ? $item->{$column_name} : ''; } } /** * This private function formats a column value for currency. * * @since 3.0 * * @param Order_Item|Order_Adjustment $item Item object. * @param string $column_name ID of the column being displayed. * @param false|float $amount_override Amount override, in case it's not in the order item. * * @return string Formatted amount. */ private function format_currency( $item, $column_name, $amount_override = false ) { $symbol = $this->get_currency_symbol( $item->order_id ); $currency_pos = edd_get_option( 'currency_position', 'before' ); $formatted_amount = ''; if ( 'before' === $currency_pos ) { $formatted_amount .= $symbol; } // Order Adjustments do not have an `amount` column. We can use `subtotal` instead. if ( 'amount' === $column_name && $item instanceof Order_Adjustment ) { $column_name = 'subtotal'; } $amount = false !== $amount_override ? $amount_override : $item->{$column_name}; $formatted_amount .= '' . edd_format_amount( $amount, true, $this->get_order_currency_decimals( $item->order_id ) ) . ''; if ( 'after' === $currency_pos ) { $formatted_amount .= $symbol; } return $formatted_amount; } /** * This private function returns the form input for refundable items, * or amounts for items which have already been refunded. * * @param Order_Item $item The item object. * @param string $column_name ID of the column being displayed. * @param string $item_id Unique ID of the order item for the refund modal. * @param string $object_type The item type. * @return string */ private function get_adjustable_column( $item, $column_name, $item_id, $object_type ) { if ( 'refunded' === $item->status ) { return $this->format_currency( $item, $column_name, 0 ); } $currency_pos = edd_get_option( 'currency_position', 'before' ); // Maximum amounts that can be refunded. $refundable_amounts = $item->get_refundable_amounts(); $amount_remaining = array_key_exists( $column_name, $refundable_amounts ) ? $refundable_amounts[ $column_name ] : $item->{$column_name}; /* * Original amount. * For subtotals, we actually do subtotal minus discounts for simplicity so that the end user * doesn't have to juggle that. */ $original_amount = $item->{$column_name}; if ( 'subtotal' === $column_name && ! empty( $item->discount ) ) { $original_amount -= $item->discount; } ob_start(); ?>