Skip to content

Commit

Permalink
v3.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Apr 26, 2024
1 parent b2eb219 commit bb090b5
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 75 deletions.
2 changes: 1 addition & 1 deletion 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: 3.3.6
Version: 3.3.7
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Expand Down
32 changes: 31 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.3
* @version 3.3.7
* @since 3.2.1
* @author WPFactory
*/
Expand Down Expand Up @@ -439,4 +439,34 @@ function alg_wc_cog_generate_wpdb_prepare_placeholders_from_array( $array ) {

return '(' . join( ',', $placeholders ) . ')';
}
}

if ( ! function_exists( 'alg_wc_cog_get_admin_orders_page_url' ) ) {
/**
* alg_wc_cog_get_admin_orders_page_url
*
* @version 3.3.7
* @since 3.3.7
*
* @return string
*/
function alg_wc_cog_get_admin_orders_page_url() {
return class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) && wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
? admin_url( 'admin.php?page=wc-orders' )
: admin_url( 'edit.php?post_type=shop_order' );
}
}

if ( ! function_exists( 'alg_wc_cog_get_option' ) ) {
/**
* alg_wc_cog_get_option.
*
* @version 3.3.7
* @since 3.3.7
*
* @return false|mixed|null
*/
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 );
}
}
15 changes: 13 additions & 2 deletions includes/class-alg-wc-cog-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Core Class.
*
* @version 2.9.4
* @version 3.3.7
* @since 1.0.0
* @author WPFactory
*/
Expand Down Expand Up @@ -78,10 +78,19 @@ class Alg_WC_Cost_of_Goods_Core {
*/
public $bulk_edit_tool;

/**
* Options.
*
* @since 3.3.7
*
* @var Alg_WC_Cost_of_Goods_Options
*/
public $options;

/**
* Constructor.
*
* @version 2.8.2
* @version 3.3.7
* @since 1.0.0
* @todo [next] add "delete all (products and/or orders) meta" tool
* @todo [next] add option to enter costs *with taxes*
Expand All @@ -99,6 +108,8 @@ class Alg_WC_Cost_of_Goods_Core {
* @todo [maybe] add option to change meta keys prefix (i.e. `_alg_wc_cog`)
*/
function __construct() {
require_once( 'class-alg-wc-cog-options.php' );
$this->options = new Alg_WC_Cost_of_Goods_Options();
// Background process.
$this->init_bkg_process();
// Analytics.
Expand Down
52 changes: 52 additions & 0 deletions includes/class-alg-wc-cog-options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Cost of Goods for WooCommerce - Options.
*
* @version 3.3.7
* @since 3.3.7
* @author WPFactory
*/

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

if ( ! class_exists( 'Alg_WC_Cost_of_Goods_Options' ) ) {

class Alg_WC_Cost_of_Goods_Options {

/**
* Options.
*
* @since 3.3.7
*
* @var array
*/
protected $options = array();

/**
* get_option.
*
* @version 3.3.7
* @since 3.3.7
*
* @param $option
* @param $default_value
* @param $get_value_from_cache
*
* @return false|mixed|null
*/
function get_option( $option, $default_value = false, $get_value_from_cache = true ) {
if (
! isset( $this->options[ $option ] ) ||
! $get_value_from_cache
) {
$this->options[ $option ] = get_option( $option, $default_value );
}

return $this->options[ $option ];
}

}

}
16 changes: 10 additions & 6 deletions includes/class-alg-wc-cog-orders-meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Orders Meta Boxes Class.
*
* @version 3.3.6
* @version 3.3.7
* @since 2.2.0
* @author WPFactory
*/
Expand Down Expand Up @@ -125,7 +125,7 @@ function add_order_meta_box() {
/**
* render_order_meta_box.
*
* @version 3.1.4
* @version 3.3.7
* @since 1.4.0
* @todo [maybe] order total
*/
Expand All @@ -136,19 +136,21 @@ function render_order_meta_box( $post ) {
return;
}
$cost = $order->get_meta( '_alg_wc_cog_order_' . 'cost', true );
$cost = apply_filters( 'alc_wc_cog_order_metabox_value', $cost, array( 'invert' => true, 'order' => $order ) );
$handling_fee = $order->get_meta( '_alg_wc_cog_order_' . 'handling_fee', true );
$profit = $order->get_meta( '_alg_wc_cog_order_' . 'profit', true );
$profit = apply_filters( 'alc_wc_cog_order_metabox_value', $profit, array( 'invert' => true, 'order' => $order ) );
$profit_percent = $order->get_meta( '_alg_wc_cog_order_' . 'profit_percent', true );
$profit_margin = $order->get_meta( '_alg_wc_cog_order_' . 'profit_margin', true );
$profit_template = get_option( 'alg_wc_cog_orders_profit_html_template', '%profit%' );
$profit_placeholders = array(
'%profit%' => alg_wc_cog()->core->orders->format_order_column_value( $profit, 'profit' ),
'%profit%' => alg_wc_cog()->core->orders->format_order_column_value( $profit, 'profit', apply_filters( 'alc_wc_cog_order_metabox_value_format_args', array(), array( 'order' => $order ) ) ),
'%profit_percent%' => alg_wc_cog()->core->orders->format_order_column_value( $profit_percent, 'profit_percent' ),
'%profit_margin%' => alg_wc_cog()->core->orders->format_order_column_value( $profit_margin, 'profit_margin' ),
);
$profit_html = str_replace( array_keys( $profit_placeholders ), $profit_placeholders, $profit_template );
$table_args = array( 'table_heading_type' => 'vertical', 'table_class' => 'widefat', 'columns_styles' => array( '', 'text-align:right;' ) );
$cost_html = apply_filters( 'alg_wc_cog_order_metabox_cost_value_html', alg_wc_cog_format_cost( $cost ), $cost, $order_id );
$cost_html = apply_filters( 'alg_wc_cog_order_metabox_cost_value_html', alg_wc_cog_format_cost( $cost, apply_filters( 'alc_wc_cog_order_metabox_value_format_args', array(), array( 'order' => $order ) ) ), $cost, $order_id );
$table_data = array(
array( __( 'Cost', 'cost-of-goods-for-woocommerce' ), ( '' !== $cost ? '<span style="color:red;">' . $cost_html . '</span>' : '' ) ),
array( __( 'Profit', 'cost-of-goods-for-woocommerce' ), ( '' !== $profit ? '<span style="color:green;">' . $profit_html . '</span>' : '' ) ),
Expand All @@ -175,8 +177,9 @@ function render_order_meta_box( $post ) {
$cost_meta_keys = apply_filters( 'alg_wc_cog_cost_meta_keys', $cost_meta_keys );
foreach ( $cost_meta_keys as $key => $value ) {
$cost = $order->get_meta( $key, true );
$cost = apply_filters( 'alc_wc_cog_order_metabox_value', $cost, array( 'invert' => true, 'order' => $order ) );
if ( ! empty( $cost ) && 0 != $cost ) {
$table_data[] = array( $value, alg_wc_cog_format_cost( $cost ) );
$table_data[] = array( $value, alg_wc_cog_format_cost( $cost, apply_filters( 'alc_wc_cog_order_metabox_value_format_args', array(), array( 'order' => $order ) ) ) );
}
}
if ( count( $table_data ) > 0 ) {
Expand All @@ -189,8 +192,9 @@ function render_order_meta_box( $post ) {
$extra_profit_meta_keys = apply_filters( 'alg_wc_cog_extra_profit_meta_keys', $extra_profit_meta_keys );
foreach ( $extra_profit_meta_keys as $key => $value ) {
$cost = $order->get_meta( $key, true );
$cost = apply_filters( 'alc_wc_cog_order_metabox_value', $cost, array( 'invert' => true, 'order' => $order ) );
if ( 0 != $cost && ! empty( $cost ) ) {
$table_data[] = array( $value, alg_wc_cog_format_cost( $cost ) );
$table_data[] = array( $value, alg_wc_cog_format_cost( $cost, apply_filters( 'alc_wc_cog_order_metabox_value_format_args', array(), array( 'order' => $order ) ) ) );
}
}
if ( count( $table_data ) > 0 ) {
Expand Down
15 changes: 9 additions & 6 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.3.6
* @version 3.3.7
* @since 2.1.0
* @author WPFactory
*/
Expand Down Expand Up @@ -879,7 +879,7 @@ function add_order_columns( $columns ) {
/**
* render_order_columns.
*
* @version 3.1.6
* @version 3.3.7
* @since 1.0.0
* @todo [later] order status for the fee columns
* @todo [later] forecasted profit `$value = $line_total * $average_profit_margin`
Expand All @@ -898,18 +898,21 @@ function render_order_columns( $column, $order_id ) {
$order = wc_get_order( $order_id );
$key = $this->get_order_column_key( $column );
$value = $order->get_meta( $key, true );
echo( '' !== $value ? $this->format_order_column_value( $value, $column ) : '' );
if ( in_array( $column, array( 'profit', 'cost' ) ) ) {
$value = apply_filters( 'alc_wc_cog_order_admin_column_value', $value, array( 'invert' => true, 'order' => $order ) );
}
echo( '' !== $value ? $this->format_order_column_value( $value, $column, apply_filters( 'alc_wc_cog_order_admin_column_value_format_args', array(), array( 'order' => $order ) ) ) : '' );
}
}

/**
* format_order_column_value.
*
* @version 2.2.0
* @version 3.3.7
* @since 2.2.0
*/
function format_order_column_value( $value, $column ) {
return ( in_array( $column, array( 'profit_percent', 'profit_margin' ) ) ? sprintf( '%0.2f%%', $value ) : wc_price( $value ) );
function format_order_column_value( $value, $column, $wc_price_args = null ) {
return ( in_array( $column, array( 'profit_percent', 'profit_margin' ) ) ? sprintf( '%0.2f%%', $value ) : wc_price( $value, $wc_price_args ) );
}

/**
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.3.6';
public $version = '3.3.7';

/**
* @since 1.0.0
Expand Down
35 changes: 30 additions & 5 deletions includes/settings/class-alg-wc-cog-settings-currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Currencies Section Settings.
*
* @version 3.2.3
* @version 3.3.7
* @since 2.2.0
* @author WPFactory
*/
Expand All @@ -28,7 +28,7 @@ function __construct() {
/**
* get_settings.
*
* @version 2.8.7
* @version 3.3.7
* @since 2.2.0
* @todo [next] exclude `$wc_currency` from `get_woocommerce_currencies()`?
* @todo [maybe] `alg_wc_cog_currencies_wmc`: add link to the plugin on wp.org?
Expand All @@ -39,15 +39,17 @@ function get_settings() {
$multicurrency_order_calculation_opts = array(
array(
'title' => __( 'Multi-currency management', 'cost-of-goods-for-woocommerce' ),
'desc' => sprintf( __( 'Calculate %s from orders in non-default shop currency based on custom exchange rates.', 'cost-of-goods-for-woocommerce' ), '<strong>' . __( 'profit', 'cost-of-goods-for-woocommerce' ) . '</strong>' ). ' ' .
__( 'The order profit will be calculated in the default shop base currency.', 'cost-of-goods-for-woocommerce' ) ,
'desc' => __( 'Some notes:', 'cost-of-goods-for-woocommerce' ) . '<br />' .
alg_wc_cog_array_to_string( array(
__( 'All COG related metas, such as profit and costs will be saved in the shop base currency.', 'cost-of-goods-for-woocommerce' ),
__( 'All costs should be always set with the shop base currency, including cost fields present on orders.', 'cost-of-goods-for-woocommerce' ),
), array( 'item_template' => '<li>{value}</li>', 'glue' => '' ) ),
'type' => 'title',
'id' => 'alg_wc_cog_currencies_options',
),
array(
'title' => __( 'Multi-currency management', 'cost-of-goods-for-woocommerce' ),
'desc' => sprintf( __( 'Enable %s feature', 'cost-of-goods-for-woocommerce' ), strtolower( __( 'Multi-currency management', 'cost-of-goods-for-woocommerce' ) ) ),
//'desc_tip' => __( 'The order profit will be calculated in the default shop base currency.', 'cost-of-goods-for-woocommerce' ),
'type' => 'checkbox',
'id' => 'alg_wc_cog_currencies_enabled',
'default' => 'no',
Expand All @@ -56,6 +58,29 @@ function get_settings() {
'hide' => true
)
),
array(
'title' => __( 'Order values', 'cost-of-goods-for-woocommerce' ),
'desc' => __( 'Display COG related values from the order, such as costs and profit, in the currency of the order', 'cost-of-goods-for-woocommerce' ),
'desc_tip' => sprintf(__( 'The affected areas are the %s and the order page on the admin.', 'cost-of-goods-for-woocommerce' ), '<a href="' . alg_wc_cog_get_admin_orders_page_url() . '">' . __( 'order listing page', 'cost-of-goods-for-woocommerce' ) . '</a>'),
'type' => 'checkbox',
'id' => 'alg_wc_cog_currencies_display_order_currency_values',
'default' => 'yes',
'custom_attributes' => apply_filters( 'alg_wc_cog_settings', array( 'disabled' => 'disabled' ) ),
'wpfse_data' => array(
'hide' => true
)
),
array(
'title' => __( 'COG order fields currency', 'cost-of-goods-for-woocommerce' ),
'desc' => __( 'Force shop base currency on COG order fields', 'cost-of-goods-for-woocommerce' ),
'type' => 'checkbox',
'id' => 'alg_wc_cog_currencies_force_sb_currency_cog_order_fields',
'default' => 'yes',
'custom_attributes' => apply_filters( 'alg_wc_cog_settings', array( 'disabled' => 'disabled' ) ),
'wpfse_data' => array(
'hide' => true
)
),
array(
'title' => __( 'Currencies', 'cost-of-goods-for-woocommerce' ),
'desc_tip' => __( 'Choose currencies you want to set exchange rates for, and "Save changes" - new settings fields will be displayed.', 'cost-of-goods-for-woocommerce' ),
Expand Down
Loading

0 comments on commit bb090b5

Please sign in to comment.