-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | ||
} |