From a46da8446359368394926775e058b3eda99b21d9 Mon Sep 17 00:00:00 2001 From: AashikP <17475174+AashikP@users.noreply.github.com> Date: Sun, 23 May 2021 14:31:18 +0530 Subject: [PATCH] initial commit --- .gitattributes | 9 +++++++ LICENSE => LICENSE.txt | 0 README.md | 3 ++- item-total-for-wc.php | 58 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .gitattributes rename LICENSE => LICENSE.txt (100%) create mode 100644 item-total-for-wc.php diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..da35e71 --- /dev/null +++ b/.gitattributes @@ -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 \ No newline at end of file diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/README.md b/README.md index ed921cf..45819da 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/item-total-for-wc.php b/item-total-for-wc.php new file mode 100644 index 0000000..8066c9d --- /dev/null +++ b/item-total-for-wc.php @@ -0,0 +1,58 @@ +' . 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' ) ) . ''; + } + 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 = ''; + $test .= '
'; + $test .= wc_price( $price, array( 'currency' => $order->get_currency() ) ); + $test .= '
'; + echo $test; + } + add_action( 'woocommerce_admin_order_item_values', 'ap_display_item_total' ); +}