Skip to content

Commit

Permalink
v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Jun 13, 2023
1 parent ee6fbbf commit 16b0ed4
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 37 deletions.
4 changes: 2 additions & 2 deletions cost-of-goods-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Cost of Goods for WooCommerce
Plugin URI: https://wpfactory.com/item/cost-of-goods-for-woocommerce/
Description: Save product purchase costs (cost of goods) in WooCommerce. Beautifully.
Version: 2.9.8
Version: 3.0.0
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Expand Down Expand Up @@ -72,7 +72,7 @@ final class Alg_WC_Cost_of_Goods {
* @var string
* @since 1.0.0
*/
public $version = '2.9.8';
public $version = '3.0.0';

/**
* @var Alg_WC_Cost_of_Goods The single instance of the class
Expand Down
56 changes: 53 additions & 3 deletions includes/analytics/class-alg-wc-cog-analytics-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Analytics - Orders.
*
* @version 2.9.8
* @version 3.0.0
* @since 2.4.5
* @author WPFactory
*/
Expand All @@ -16,8 +16,8 @@ class Alg_WC_Cost_of_Goods_Analytics_Orders {
/**
* Constructor.
*
* @version 2.4.8
* @since 2.4.5
* @version 3.0.0
* @since 3.0.0
*
* @see https://github.com/woocommerce/woocommerce-admin/tree/master/docs/examples/extensions
* @see https://woocommerce.wordpress.com/2020/02/20/extending-wc-admin-reports/
Expand Down Expand Up @@ -56,6 +56,10 @@ function __construct() {
add_filter( 'woocommerce_admin_orders_report_export_column_names', array( $this, 'add_profit_columns_names_to_export' ), PHP_INT_MAX, 2 );
add_filter( 'alg_wc_cog_analytics_orders_profit_total_validation', array( $this, 'add_profit_total_column_if_option_is_enabled' ) );

// Individual Costs export
add_filter( 'woocommerce_export_admin_orders_report_row_data', array( $this, 'add_individual_costs_row_data_to_export' ), PHP_INT_MAX, 2 );
add_filter( 'woocommerce_admin_orders_report_export_column_names', array( $this, 'add_individual_costs_columns_names_to_export' ), PHP_INT_MAX, 2 );

// Test, Debug
// woocommerce_analytics_orders_stats_select_query
// woocommerce_analytics_orders_stats_query_args
Expand All @@ -79,6 +83,52 @@ function __construct() {
return $param;
}*/

/**
* add_individual_costs_columns_names_to_export.
*
* @version 3.0.0
* @since 3.0.0
*
* @param $columns
* @param $exporter
*
* @return mixed
*/
function add_individual_costs_columns_names_to_export( $columns, $exporter ) {
if ( 'yes' === get_option( 'alg_wc_cog_analytics_orders_individual_costs', 'no' ) ) {
$columns['items_cost'] = __( 'Items cost', 'cost-of-goods-for-woocommerce' );
$columns['shipping_cost'] = __( 'Shipping cost', 'cost-of-goods-for-woocommerce' );
$columns['gateway_cost'] = __( 'Gateway cost', 'cost-of-goods-for-woocommerce' );
$columns['extra_cost'] = __( 'Extra cost', 'cost-of-goods-for-woocommerce' );
$columns['shipping_classes_cost'] = __( 'Shipping classes cost', 'cost-of-goods-for-woocommerce' );
}

return $columns;
}

/**
* add_individual_costs_row_data_to_export.
*
* @version 3.0.0
* @since 3.0.0
*
* @param $row
* @param $item
*
* @return mixed
*/
function add_individual_costs_row_data_to_export( $row, $item ) {
if ( 'yes' === get_option( 'alg_wc_cog_analytics_orders_individual_costs', 'no' ) ) {
$row['items_cost'] = $item['items_cost'];
$row['shipping_cost'] = $item['shipping_cost'];
$row['gateway_cost'] = $item['gateway_cost'];
$row['extra_cost'] = $item['extra_cost'];
$row['shipping_classes_cost'] = $item['shipping_classes_cost'];
}

return $row;
}

/**
* add_analytics_localization_info.
*
Expand Down
16 changes: 15 additions & 1 deletion includes/class-alg-wc-cog-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function get_product_handling_fee( $product_id, $args = null ) {
/**
* get_product_price.
*
* @version 2.5.2
* @version 2.9.9
* @since 2.3.9
*
* @param $product
Expand All @@ -411,6 +411,19 @@ function get_product_handling_fee( $product_id, $args = null ) {
* @return mixed
*/
function get_product_price( $product, $args = null ) {

// Check if $product is a valid product object. If not, try loading it.
if ( !( $product instanceof WC_Product ) ) {
$product_id = $product;
$product = wc_get_product( $product_id );

// If it's still not a valid product object, log an error and return false
if ( !( $product instanceof WC_Product ) ) {
error_log( "Invalid product ID: $product_id" );
return false; // or you might return a default value instead
}
}

$args = wp_parse_args( $args, array(
'method' => get_option( 'alg_wc_cog_products_get_price_method', 'wc_get_price_excluding_tax' ),
'params' => array(),
Expand All @@ -419,6 +432,7 @@ function get_product_price( $product, $args = null ) {
$params = array_merge( array( $product ), $args['params'] );
$return = call_user_func_array( $args['method'], $params );
return $args['return_zero_if_empty'] && empty( $return ) ? 0 : (float) $return;

}

/**
Expand Down
63 changes: 34 additions & 29 deletions langs/cost-of-goods-for-woocommerce.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the GNU General Public License v3.0.
msgid ""
msgstr ""
"Project-Id-Version: cost-of-goods-for-woocommerce 2.9.8\n"
"Project-Id-Version: cost-of-goods-for-woocommerce 3.0.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cost-of-goods-for-woocommerce\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2023-05-16T16:37:36+02:00\n"
"POT-Creation-Date: 2023-06-13T23:03:40+02:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.7.1\n"
"X-Domain: cost-of-goods-for-woocommerce\n"
Expand Down Expand Up @@ -44,7 +44,37 @@ msgstr ""
msgid "Disabled options can be unlocked using <a href=\"%s\" target=\"_blank\"><strong>%s</strong></a>"
msgstr ""

#: includes/analytics/class-alg-wc-cog-analytics-orders.php:309
#: includes/analytics/class-alg-wc-cog-analytics-orders.php:99
#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:36
msgid "Items cost"
msgstr ""

#: includes/analytics/class-alg-wc-cog-analytics-orders.php:100
#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:42
msgid "Shipping cost"
msgstr ""

#: includes/analytics/class-alg-wc-cog-analytics-orders.php:101
#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:48
msgid "Gateway cost"
msgstr ""

#: includes/analytics/class-alg-wc-cog-analytics-orders.php:102
#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:54
msgid "Extra cost"
msgstr ""

#: includes/analytics/class-alg-wc-cog-analytics-orders.php:103
#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:60
msgid "Shipping classes cost"
msgstr ""

#: includes/analytics/class-alg-wc-cog-analytics-orders.php:359
#: includes/analytics/class-alg-wc-cog-analytics-revenue.php:47
#: includes/analytics/class-alg-wc-cog-analytics-stock.php:88
#: includes/class-alg-wc-cog-orders-meta-boxes.php:145
Expand All @@ -69,7 +99,7 @@ msgstr ""
msgid "Cost"
msgstr ""

#: includes/analytics/class-alg-wc-cog-analytics-orders.php:345
#: includes/analytics/class-alg-wc-cog-analytics-orders.php:395
#: includes/analytics/class-alg-wc-cog-analytics-revenue.php:48
#: includes/analytics/class-alg-wc-cog-analytics-stock.php:89
#: includes/class-alg-wc-cog-orders-meta-boxes.php:146
Expand Down Expand Up @@ -2890,31 +2920,6 @@ msgstr ""
msgid "Sale price"
msgstr ""

#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:36
msgid "Items cost"
msgstr ""

#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:42
msgid "Shipping cost"
msgstr ""

#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:48
msgid "Gateway cost"
msgstr ""

#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:54
msgid "Extra cost"
msgstr ""

#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/orders.js:60
msgid "Shipping classes cost"
msgstr ""

#: includes/analytics/build/index.js:1
#: includes/analytics/src/modules/categories.js:86
#: includes/analytics/src/modules/orders.js:163
Expand Down
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== Cost of Goods for WooCommerce ===
Contributors: wpcodefactory, karzin, kerbhavik, jaedm97, algoritmika, anbinder
Contributors: wpcodefactory, karzin, kerbhavik, jaedm97, algoritmika, anbinder, omardabbas, kousikmukherjeeli
Tags: woocommerce, cost, cost of goods, cog, cost of goods sold, cogs, woo commerce
Requires at least: 4.4
Tested up to: 6.2
Stable tag: 2.9.8
Stable tag: 3.0.0
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -98,6 +98,12 @@ And then you can follow these steps:

== Changelog ==

= 3.0.0 - 13/06/2023 =
* Dev - Tools - Analytics - Orders - Individual elements should be present on the CSV.

= 2.9.9 - 25/05/2023 =
* Update function Alg_WC_Cost_of_Goods_Products() ->get_product_price() with condition if product object exist or not .

= 2.9.8 - 16/05/2023 =
* Fix - Analytics - Update dependencies.
* Dev - Tools - Analytics - Orders - New option: Add columns for individual elements from the costs total.
Expand Down

0 comments on commit 16b0ed4

Please sign in to comment.