Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AashikP committed May 23, 2021
1 parent c7a82a3 commit a46da84
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set the default behavior, in case people don't have `core.autocrlf` set.
* text=auto

# Declare files that will always have LF line endings on checkout.
*.php text eol=lf

# Remove files for archives generated using `git archive`.
/.* export-ignore
README.md export-ignore
File renamed without changes.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# item-total-for-wc
Simple plugin to display Item total in the order details page.

This is a simple extension for WooCommerce to display Item total in the order details page.
58 changes: 58 additions & 0 deletions item-total-for-wc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Plugin Name: Item total for WooCommerce
* Description: Simple plugin to display Item total in the order details page.
* Version: 1.0.0
* Author: AashikP
* Author URI: https://aashikp.com
* Text Domain: item-total-for-wc
* Requires at least: 4.9.14
* Requires PHP: 7.3.5
* WC requires at least: 3.5.0
* WC tested up to: 5.3.0
*
* @package Item-Total-for-WC
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Check if WooCommerce is active
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {

/**
* Display tax included price under order details page.
*/
function ap_item_total_header() {
echo '<th width=100%;">' . esc_html__( 'Item Total', 'item-total-for-wc' ) . wc_help_tip( esc_html__( 'Item total = [Cost * Qty]+Tax total. This is the actual product total paid by the customer, and Cost = Price of the product minus Discounts (if any)', 'item-total-for-wc' ) ) . '</th>';
}
add_action( 'woocommerce_admin_order_item_headers', 'ap_item_total_header' );

/**
* Display the total tax for a line item.
*
* @param object $product Product object.
*/
function ap_display_item_total( $product ) {
global $post;
if ( ! is_int( $thepostid ) ) {
$thepostid = $post->ID;
}
$order = wc_get_order( $thepostid );
$order_items = $order->get_items();
foreach ( $order->get_items() as $item_id => $item ) {
if ( $item['product_id'] === $product->id ) {
$price = $item['total_tax'] + $item['total'];
}
}
$test = '<td class="item_total_cost">';
$test .= '<div class="view">';
$test .= wc_price( $price, array( 'currency' => $order->get_currency() ) );
$test .= '</span></div></td>';
echo $test;
}
add_action( 'woocommerce_admin_order_item_values', 'ap_display_item_total' );
}

0 comments on commit a46da84

Please sign in to comment.