Skip to content

Commit

Permalink
v3.4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Jul 17, 2024
1 parent 41410b3 commit 17a52ff
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 111 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,13 +3,13 @@
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: 3.4.7
Version: 3.4.8
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Domain Path: /langs
Copyright: © 2024 WPFactory
WC tested up to: 9.0
WC tested up to: 9.1
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
Expand Down
17 changes: 16 additions & 1 deletion includes/alg-wc-cog-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Functions.
*
* @version 3.3.7
* @version 3.4.8
* @since 3.2.1
* @author WPFactory
*/
Expand Down Expand Up @@ -469,4 +469,19 @@ function alg_wc_cog_get_admin_orders_page_url() {
function alg_wc_cog_get_option( $option, $default_value = false, $get_value_from_cache = true ) {
return alg_wc_cog()->core->options->get_option( $option, $default_value, $get_value_from_cache );
}
}

if ( ! function_exists( 'alg_wc_cog_get_ignore_item_refund_amount_default' ) ) {
/**
* alg_wc_cog_get_option.
*
* @version 3.4.8
* @since 3.4.8
*
* @return string
*/
function alg_wc_cog_get_ignore_item_refund_amount_default() {
$order_refund_calculation_method = alg_wc_cog_get_option( 'alg_wc_cog_order_refund_calculation_method', 'ignore_refunds' );
return 'profit_and_price_based_on_item_refunded_amount' === $order_refund_calculation_method ? 'yes' : 'no';
}
}
19 changes: 10 additions & 9 deletions includes/class-alg-wc-cog-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Orders Class.
*
* @version 3.4.4
* @version 3.4.8
* @since 2.1.0
* @author WPFactory
*/
Expand Down Expand Up @@ -1281,7 +1281,7 @@ function get_shipping_total_for_percentage_fees( $order ) {
/**
* update_order_items_costs.
*
* @version 3.3.3
* @version 3.4.8
* @since 1.1.0
* @todo [maybe] filters: add more?
* @todo [maybe] `$total_price`: customizable calculation method (e.g. `$order->get_subtotal()`) (this will affect `_alg_wc_cog_order_profit_margin`)
Expand Down Expand Up @@ -1325,7 +1325,7 @@ function update_order_items_costs( $args ) {
$shipping_class_cost_fixed_total = 0;
$shipping_class_cost_percent_total = 0;
$shipping_classes_cost_total = 0;
// Calculate quantity ignoring refunded items
// Calculate quantity ignoring refunded items.
$calculate_qty_excluding_refunds = 'yes' === get_option( 'alg_wc_cog_calculate_qty_excluding_refunds', 'no' );
// Order items
$items_cost = 0;
Expand All @@ -1347,8 +1347,9 @@ function update_order_items_costs( $args ) {
$per_order_fees = 0;
// Fees: Order extra cost: from meta (e.g. PayPal, Stripe etc.)
$meta_fees = 0;
// Refund calculation
$refund_calc_method = get_option( 'alg_wc_cog_order_refund_calculation_method', 'ignore_refunds' );
// Refund calculation.
$refund_profit_calc_method = get_option( 'alg_wc_cog_order_refund_calculation_method', 'ignore_refunds' );
$ignore_item_refund_amount = 'yes' === get_option( 'alg_wc_cog_ignore_item_refund_amount', alg_wc_cog_get_ignore_item_refund_amount_default() );
// Totals
$profit = 0;
$total_cost = 0;
Expand Down Expand Up @@ -1411,7 +1412,7 @@ function update_order_items_costs( $args ) {
$handling_fee = '0';
}
// calculate total profit, cost, handling fee per order items.
$quantity = $calculate_qty_excluding_refunds ? $item->get_quantity() + $order->get_qty_refunded_for_item( $item_id ) : $item->get_quantity();
$quantity = $calculate_qty_excluding_refunds ? $item->get_quantity() - abs( $order->get_qty_refunded_for_item( $item_id ) ) : $item->get_quantity();
if ( '' !== $cost || '' !== $handling_fee ) {
$cost = alg_wc_cog_sanitize_number( array(
'value' => $cost,
Expand All @@ -1420,7 +1421,7 @@ function update_order_items_costs( $args ) {
$cost = (float) $cost;
$line_cost = $cost * $quantity;
$item_line_total = $item['line_total'];
if ( 'profit_and_price_based_on_item_refunded_amount' === $refund_calc_method ) {
if ( $ignore_item_refund_amount ) {
$item_line_total -= $order->get_total_refunded_for_item( $item_id );
}
$line_total = apply_filters( 'alg_wc_cog_order_line_total', $item_line_total, $order );
Expand Down Expand Up @@ -1629,9 +1630,9 @@ function update_order_items_costs( $args ) {
}
// Readjust profit on refunded orders
if ( $order_total_refunded > 0 ) {
if ( 'profit_based_on_total_refunded' === $refund_calc_method ) {
if ( 'profit_based_on_total_refunded' === $refund_profit_calc_method ) {
$profit -= $order_total_refunded;
} elseif ( 'profit_by_netpayment_and_cost_difference' === $refund_calc_method ) {
} elseif ( 'profit_by_netpayment_and_cost_difference' === $refund_profit_calc_method ) {
$the_total = $order->get_total();
$tax_percent = $the_total > 0 ? 1 - ( $order->get_total_tax() / $the_total ) : 1;
$net_payment = apply_filters( 'alg_wc_cog_order_net_payment', $order->get_total() - $order_total_refunded );
Expand Down
2 changes: 1 addition & 1 deletion includes/class-alg-wc-cog.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class Alg_WC_Cost_of_Goods {
* @since 1.0.0
* @var string
*/
public $version = '3.4.7';
public $version = '3.4.8';

/**
* @since 1.0.0
Expand Down
42 changes: 22 additions & 20 deletions includes/settings/class-alg-wc-cog-settings-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Orders Section Settings.
*
* @version 3.2.7
* @version 3.4.8
* @since 1.7.0
* @author WPFactory
*/
Expand All @@ -28,7 +28,7 @@ function __construct() {
/**
* get_settings.
*
* @version 3.2.7
* @version 3.4.8
* @since 1.7.0
* @todo [later] `alg_wc_cog_order_prepopulate_in_ajax`: remove (i.e. always enabled)
* @todo [later] `alg_wc_cog_order_save_items_ajax`: remove (i.e. always enabled)
Expand Down Expand Up @@ -334,36 +334,38 @@ function get_settings() {
array(
'title' => __( 'Refunds', 'cost-of-goods-for-woocommerce' ),
'desc' =>
__( "Set up how refunds will affect the cost and profit.", 'cost-of-goods-for-woocommerce' ) . ' ' .
sprintf(
__( "It's necessary to add the %s status on %s option in order to see refunded orders on reports.", 'cost-of-goods-for-woocommerce' ),
'<strong>' . __( 'Refunded', 'cost-of-goods-for-woocommerce' ) . '</strong>',
'<strong>' . __( 'Tools > Orders report: Order status', 'cost-of-goods-for-woocommerce' ) . '</strong>'
) . '<br />' .
sprintf(
__( "Enable %s options to automatically calculate refund costs.", 'cost-of-goods-for-woocommerce' ),
'<strong>' . __( 'Advanced > Force costs update', 'cost-of-goods-for-woocommerce' ) . '</strong>'
) . '<br />' .
__( "It's necessary to recalculate order's cost and profit after you change these settings.", 'cost-of-goods-for-woocommerce' ),
__( "Most probably, enabling the options %s and %s should be enough in order to ignore refunded items from profit calculation.", 'cost-of-goods-for-woocommerce' ),
'<strong>' . __( 'Ignore refunded item cost', 'cost-of-goods-for-woocommerce' ) . '</strong>',
'<strong>' . __( 'Ignore item refund amount', 'cost-of-goods-for-woocommerce' ) . '</strong>'
) . '<br /><br />' .
sprintf( __( "It's necessary to manually update the order after a refund. If you change these settings you can use our %s to update the orders. ", 'cost-of-goods-for-woocommerce' ), '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=alg_wc_cost_of_goods&section=tools' ) . '">' . __( 'Orders Recalculation Tool' ) . '</a>' ),
'type' => 'title',
'id' => 'alg_wc_cog_refund_options',
),
array(
'title' => __( 'Item quantity', 'cost-of-goods-for-woocommerce' ),
'desc' => __( 'Calculate quantity by excluding refunded items', 'cost-of-goods-for-woocommerce' ),
'desc_tip' => __( 'This will affect both the profit and the cost.', 'cost-of-goods-for-woocommerce' ),
'id' => 'alg_wc_cog_calculate_qty_excluding_refunds',
'default' => 'no',
'type' => 'checkbox',
'title' => __( 'Item cost', 'cost-of-goods-for-woocommerce' ),
'desc' => __( 'Ignore refunded item cost', 'cost-of-goods-for-woocommerce' ),
'id' => 'alg_wc_cog_calculate_qty_excluding_refunds',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Item total', 'cost-of-goods-for-woocommerce' ),
'desc' => __( 'Ignore item refund amount', 'cost-of-goods-for-woocommerce' ),
'id' => 'alg_wc_cog_ignore_item_refund_amount',
'default' => alg_wc_cog_get_ignore_item_refund_amount_default(),
'type' => 'checkbox',
),
array(
'title' => __( 'Refund calculation', 'cost-of-goods-for-woocommerce' ),
'title' => __( 'Profit calculation', 'cost-of-goods-for-woocommerce' ),
'id' => 'alg_wc_cog_order_refund_calculation_method',
'default' => 'ignore_refunds',
'type' => 'radio',
'options' => array(
'ignore_refunds' => __( 'Profit ignore refunds', 'cost-of-goods-for-woocommerce' ),
'ignore_refunds' => __( 'Use default profit calculation mechanism', 'cost-of-goods-for-woocommerce' ),
'profit_based_on_total_refunded' => __( 'Subtract total refunded from profit', 'cost-of-goods-for-woocommerce' ),
'profit_and_price_based_on_item_refunded_amount' => __( 'Subtract each item\'s refund amount from profit', 'cost-of-goods-for-woocommerce' ),
'profit_by_netpayment_and_cost_difference' => __( 'Calculate profit by the difference between Net Payment and Cost', 'cost-of-goods-for-woocommerce' ),
)
),
Expand Down
Loading

0 comments on commit 17a52ff

Please sign in to comment.