oont-contents/themes/oont-themev2/inc/templates/admin/softoba-exchange-items-table.php
2025-02-08 15:10:23 +01:00

328 lines
No EOL
17 KiB
PHP

<?php
$request = new SOFTOBA_Exchange_Request( $post->ID );
if ( ! ( $request instanceof SOFTOBA_Exchange_Request && $request->exists() ) ) {
return;
}
$finished_request = apply_filters( 'softoba_finished_request', ( 'softoba-approved' == $request->status || 'softoba-rejected' == $request->status || 'trash' == $request->status ), $request );
$order = wc_get_order( $request->order_id );
$order_id = $order->get_id();
$order_number = $order->get_order_number();
$order_total = $order->get_total() - $order->get_total_refunded();
$product = $request->product_id ? wc_get_product( $request->product_id ) : '';
$tax_enabled = wc_tax_enabled();
$exchange_details = get_post_meta( $order_id, 'sobaoba_exchange_products', true );
?>
<div class="softoba_items_info">
<?php
$href = admin_url( 'post.php?post=' . $order_id . '&action=edit' );
$title = $order_id == $order_number ? sprintf( esc_html__( 'Go to order #%d', 'astra' ), $order_id ) : sprintf( esc_html__( 'Go to order %s', 'astra' ), $order_number );
$order_link = '<a href="' . $href . '" title="' . $title . '">';
$order_link .= $order_id == $order_number ? '#' . $order_id . '</a>' : $order_number . '</a>';
$status_title = softoba_get_request_status_by_key( $request->status );
// $src = SOFTOBA_ASSETS_URL . 'images/' . $request->status . '.png';
?>
<input type="hidden" id="softoba_ex_request_id" value="<?php echo $request->ID; ?>">
<input type="hidden" id="softoba_ex_request_status" value="<?php echo $request->status; ?>">
<input type="hidden" id="softoba_ex_request_is_closed" value="<?php echo $request->is_closed; ?>">
<input type="hidden" id="softoba_ex_order_id" value="<?php echo $request->order_id; ?>">
<?php if ( 'trash' == $request->status ) : ?>
<span class="softoba_trash_status_icon"></span>
<?php endif; ?>
<h2 style="display: inline-block; vertical-align: super;font-size:20px;">
<?php printf( esc_html_x( 'Exchange Request %s for order %s', 'Request [request ID] for order [order ID]', 'astra' ), '#' . $request->ID, $order_link ); ?>
</h2>
<div class="softoba_before_items_table">
<?php do_action( 'softoba_before_items_table_start', $request ); ?>
<?php
$customer = version_compare( WC()->version, '3.0.0', '<' ) ? $request->get_customer_link_legacy() : $request->get_customer_link();
$get_variation = new WC_Product_Variation( $request->variation_id );
$get_variation_attributes = $get_variation->get_variation_attributes();
$get_ordered_variation = wc_get_formatted_variation( $get_variation_attributes, true );
if ( $request->whole_order ) {
$info = sprintf( esc_html__( '%s made a request for the whole order', 'astra' ), $customer );
} else {
$span_product = $product ? '<span style="text-decoration: underline;">' . $product->get_title() . '</span>': '';
$span_qty = '<span title="' . esc_html__( 'Quantity requested', 'astra' ) . '">' . $request->qty . '</span>';
$info = sprintf( esc_html__( '%s made a request for exchange', 'astra' ), $customer );
}
?>
<div><?php echo $info; ?></div>
<?php do_action( 'softoba_before_items_table_end', $request ); ?>
</div>
<div style="overflow: auto;">
<table class="softoba_items_table">
<thead>
<tr>
<th style="text-align:left;" colspan="2"><?php esc_html_e( 'Item', 'astra' ); ?></th>
<th><?php esc_html_e( 'Ordered variant', 'astra' ); ?></th>
<th><?php esc_html_e( 'Requested variant', 'astra' ); ?></th>
<th><?php esc_html_e( 'Item value', 'astra' ); ?></th>
<th><?php esc_html_e( 'Qty', 'astra' ); ?></th>
<th class="softoba_items_table_totals"><?php esc_html_e( 'Order Total', 'astra' ); ?></th>
<th class="softoba_items_table_totals"><?php esc_html_e( 'Exchange Qty', 'astra' ); ?></th>
</tr>
</thead>
<tbody>
<?php
do_action( 'softoba_items_table_tbody_start', $request, $tax_enabled );
$refund_amount = '0';
$items = $order->get_items( array( 'line_item', 'shipping', 'fee' ) );
foreach ( $items as $item_id => $item ) {
foreach( $exchange_details['products'] as $key => $ex_product ){
if( $ex_product['item_id'] == $item_id ) {
$item_type = version_compare( WC()->version, '3.0.0', '<' ) ? $item['type'] : $item->get_type();
if ( 'line_item' == $item_type ) :
$product = empty( $item['variation_id'] ) ? wc_get_product( $item['product_id'] ) : wc_get_product( $item['variation_id'] );
if ( ! $product || ! $product->exists() ) { ?>
<tr><td><?php esc_html_e( 'The requested product does not exist.', 'astra' ); ?></td></tr>
<?php
continue;
}
$qty_requested = '0';
$return_class = 'return_product_item_oddd';
if ( $item_id == $request->item_id ) {
$qty_requested = $request->qty;
$return_class = 'return_product_item_add';
}
if( $item['qty'] !== 0 ){
$item_value = $item['line_total'] / $item['qty'];
}
$thumbnail = $product ? apply_filters( 'woocommerce_admin_order_item_thumbnail', $product->get_image( 'thumbnail', array( 'title' => '' ), false ), $item_id, $item ) : '';
$product_link = $product ? admin_url( 'post.php?post=' . $item->get_product_id() . '&action=edit' ) : '';
?>
<tr class="<?php echo esc_attr( $return_class ); ?>">
<td class="thumb">
<?php echo '<div class="wc-order-item-thumbnail">' . wp_kses_post( $thumbnail ) . '</div>'; ?>
</td>
<td>
<?php echo $product_link ? '<a href="' . esc_url( $product_link ) . '" class="wc-order-item-name">' . wp_kses_post( $item->get_name() ) . '</a>' : '<div class="wc-order-item-name">' . wp_kses_post( $item->get_name() ) . '</div>'; ?>
</td>
<td>
<?php
$get_variation = new WC_Product_Variation( $ex_product['variation_id'] );
$get_variation_attributes = $get_variation->get_variation_attributes();
echo wc_get_formatted_variation( $get_variation_attributes, true );
?>
</td>
<td>
<?php
if( $ex_product['item_id'] == $item_id ) {
$refund_amount = wc_price( $item_value, array( 'currency' => $order->get_currency() ) );
$get_variation = new WC_Product_Variation( $ex_product['ex_variation_id'] );
$get_variation_attributes = $get_variation->get_variation_attributes();
echo wc_get_formatted_variation( $get_variation_attributes, true );
}else{
echo '-';
}
?>
</td>
<td><?php echo wc_price( $item_value, array( 'currency' => $order->get_currency() ) ); ?></td>
<td><?php echo $item['qty']; ?></td>
<td class="softoba_items_table_totals">
<?php $total = $tax_enabled ? $item['line_total'] + $item['line_tax'] : $item['line_total'] ?>
<span><?php echo wc_price( $total, array( 'currency' => $order->get_currency() ) ); ?></span>
</td>
<td class="softoba_items_table_totals softoba_items_table_refund softoba_item_data">
<input type="text" size="1" readonly class="softoba_item_qty" value="<?php echo $ex_product['eqty']; ?>">
<input type="hidden" class="softoba_item_id" value="<?php echo $item_id; ?>">
<input type="hidden" class="softoba_item_value" value="<?php echo $item_value; ?>">
<input type="hidden" class="softoba_item_total" value="<?php echo $total_refund ?>">
</td>
</tr>
<?php else : ?>
<tr class="softoba_non_line_item">
<?php $item_name = version_compare( WC()->version, '3.0.0', '<' ) ? $item['name'] : $item->get_name(); ?>
<?php if ( 'shipping' == $item_type ) : ?>
<?php $shipping_total = version_compare( WC()->version, '3.0.0', '<' ) ? (float) $item['cost'] : (float) $item->get_total(); ?>
<?php
$shipping_tax = 0;
if ( $tax_enabled ) {
if ( version_compare( WC()->version, '3.0.0', '<' ) ) {
foreach ( maybe_unserialize( $item['taxes'] ) as $tax ) {
$shipping_tax += (float) $tax;
}
} else {
$shipping_tax = (float) $item->get_total_tax();
}
}
?>
<?php $shipping_sum = $tax_enabled ? $shipping_total + $shipping_tax : $shipping_total; ?>
<td><?php echo $item_name ? $item_name : esc_html__( 'Shipping', 'astra' ); ?></td>
<td></td><td></td>
<td class="softoba_items_table_totals"><?php echo wc_price( $shipping_sum, array( 'currency' => $order->get_currency() ) ); ?></td>
<td class="softoba_items_table_totals softoba_items_table_refund softoba_non_line_item_data">
<input class="softoba_non_line_item_cb" disabled type="checkbox">
<input type="hidden" class="softoba_item_id" value="<?php echo $item_id; ?>">
<input type="hidden" class="softoba_item_value" value="<?php echo $shipping_total; ?>">
<?php if ( $tax_enabled ) : ?>
<?php
$taxes_data = maybe_unserialize( $item['taxes'] );
if ( empty( $taxes_data['total'] ) ) {
$taxes = $order->get_items( 'tax' );
foreach ( $taxes as $tax_item ) {
?>
<input type="hidden" class="softoba_item_tax" data-tax_id="<?php echo $tax_item['rate_id']; ?>" value="0">
<?php
}
} else {
foreach ( $taxes_data['total'] as $tax_id => $value ) { ?>
<input type="hidden" class="softoba_item_tax" data-tax_id="<?php echo $tax_id; ?>" value="<?php echo (float) $value; ?>">
<?php }
}
?>
<input type="hidden" class="softoba_item_tax_value" value="<?php echo $shipping_tax; ?>">
<?php endif; ?>
<input type="hidden" class="softoba_item_total" value="<?php echo $shipping_sum ?>">
</td>
<td class="softoba_items_table_totals softoba_items_table_refund softoba_refund_subtotal_data"></td>
<?php endif; ?>
<?php if ( 'fee' == $item_type ) : ?>
<?php $fee_total = version_compare( WC()->version, '3.0.0', '<' ) ? (float) $item['line_total'] : (float) $item->get_total(); ?>
<?php $fee_tax = version_compare( WC()->version, '3.0.0', '<' ) ? (float) $item['line_tax'] : (float) $item->get_total_tax(); ?>
<?php $fee_sum = $tax_enabled ? $fee_total + $fee_tax : $fee_total; ?>
<td><?php echo $item_name ? $item_name : esc_html__( 'Fee', 'astra' ); ?></td>
<td></td><td></td>
<td class="softoba_items_table_totals"><?php echo wc_price( $fee_sum, array( 'currency' => $order->get_currency() ) ); ?></td>
<td class="softoba_items_table_totals softoba_items_table_refund softoba_non_line_item_data">
<input class="softoba_non_line_item_cb" disabled type="checkbox">
<input type="hidden" class="softoba_item_id" value="<?php echo $item_id; ?>">
<input type="hidden" class="softoba_item_value" value="<?php echo $fee_total; ?>">
<?php if ( $tax_enabled ) : ?>
<input type="hidden" class="softoba_item_tax_value" value="<?php echo $fee_tax; ?>">
<?php endif; ?>
<input type="hidden" class="softoba_item_total" value="<?php echo $fee_sum ?>">
</td>
<td class="softoba_items_table_totals softoba_items_table_refund softoba_refund_subtotal_data"></td>
<?php endif; ?>
</tr>
<?php endif;
}
}
}
do_action( 'softoba_items_table_tbody_end', $request, $tax_enabled );
?>
</tbody>
</table>
</div>
<div class="wc-order-data-row wc-order-totals-items wc-order-items-editable">
<table class="wc-order-totals">
<tbody>
<tr>
<?php
$order_tax = $order->get_total_tax();
$order_total = $order->get_total() - $order->get_total_refunded();
?>
<td class="label">Order Total:</td>
<td width="1%"></td>
<td class="total">
<?php
if ( $order_tax ) {
$order_total = $order_total - $order_tax;
echo wc_price( $order_total, array( 'currency' => $order->get_currency() ) );
} else {
echo $order->get_formatted_order_total();
}
?>
</td>
</tr>
</tbody>
</table>
<div class="clear"></div>
<table class="wc-order-totals" style="border-top: 1px solid #999; margin-top:12px; padding-top:12px">
<tbody>
<tr>
<td class="label label-highlight"><?php esc_html_e( 'Paid:', 'astra' ); ?><br></td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ); ?>
</td>
</tr>
<tr>
<td>
<span class="description">
<?php
if ( $order->get_payment_method_title() ) {
/* translators: 1: payment date. 2: payment method */
echo esc_html( sprintf( __( '%1$s via %2$s', 'astra' ), $order->get_date_paid()->date_i18n( get_option( 'date_format' ) ), $order->get_payment_method_title() ) );
} else {
echo esc_html( $order->get_date_paid()->date_i18n( get_option( 'date_format' ) ) );
}
// $refund_amount = wc_price( 1, array( 'currency' => $order->get_currency() ) );
?>
</span>
</td>
<td colspan="2"></td>
</tr>
</tbody>
</table>
<div class="clear"></div>
<?php if ( $order->get_total_refunded() ) : ?>
<table class="wc-order-totals" style="border-top: 1px solid #999; margin-top:12px; padding-top:12px">
<tr>
<td class="label refunded-total"><?php esc_html_e( 'Refunded', 'woocommerce' ); ?>:</td>
<td width="1%"></td>
<td class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<?php do_action( 'woocommerce_admin_order_totals_after_refunded', $order->get_id() ); ?>
<tr>
<td class="label label-highlight"><?php esc_html_e( 'Net Payment', 'woocommerce' ); ?>:</td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
</table>
<?php endif; ?>
<div class="clear"></div>
<table class="wc-order-totals"> </table>
<div class="clear"></div>
</div>
<div class="wc-order-data-row wc-order-bulk-actions wc-order-data-row-toggle">
<p class="add-items">
<input type="hidden" id="softoba_ex_whole_order" value="<?php echo $request->whole_order ? 'true' : 'false'; ?>">
<input type="hidden" id="softoba_ex_refunded_item_id" value="<?php echo $request->item_id; ?>">
<input type="hidden" id="refunded_ex_amount" value="<?php echo esc_attr( $order->get_total_refunded() ); ?>">
<input type="hidden" id="softoba_ex_order_total" value="<?php echo $order_total; ?>">
<input type="hidden" id="softoba_ex_taxes_enabled" value="<?php echo $tax_enabled; ?>">
<input type="hidden" id="softoba_ex_refund_amount" value="<?php echo $request->refund_total; ?>">
<?php if( $request->status !== 'softoba-approved' ) : ?>
<button class="button button-secondary" id="softoba_ex_reject_request_button">
<span><?php esc_html_e( 'Reject request', 'astra' ); ?></span>
</button>
<?php endif; ?>
<?php if( $request->exchange_fee === 'processing' || $request->exchange_fee === 'completed') :
if( $request->status !== 'softoba-approved' ) :
?>
<button class="button button-secondary" id="softoba_ex_processing_request_button">
<span><?php esc_html_e( 'Set to processing', 'astra' ); ?></span>
</button>
<button class="button button-secondary" id="softoba_ex_on_hold_request_button">
<span><?php esc_html_e( 'Set to on hold', 'astra' ); ?></span>
</button>
<button class="button button-secondary" id="softoba_ex_approved_request_button">
<span><?php esc_html_e( 'Approved', 'astra' ); ?></span>
</button>
<?php endif; endif; if ( $finished_request && ! $request->is_closed ) : ?>
<button class="button button-secondary tips" id="softoba_ex_close_request_button" data-tip="<?php esc_html_e( 'Close the request by stopping the messages system. This action prevents you from changing the request status.', 'astra' ); ?>">
<span><?php esc_html_e( 'Close this request', 'astra' ); ?></span>
</button>
<?php endif; ?>
</p>
<?php if ( $request->is_closed ) : ?>
<h4><?php esc_html_e( 'This request is currently closed.', 'astra' ); ?></h4>
<?php endif; ?>
</div>
</div>