Skip to content

Commit

Permalink
v3.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Dec 19, 2023
1 parent 3f93ab0 commit 9cc0ab2
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 121 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.1.8
Version: 3.1.9
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Expand Down
23 changes: 20 additions & 3 deletions includes/class-alg-wc-cog-cost-inputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Costs input.
*
* @version 2.9.4
* @version 3.1.9
* @since 2.6.4
* @author WPFactory
*/
Expand Down Expand Up @@ -67,7 +67,7 @@ function add_hooks(){
/**
* add_cost_input.
*
* @version 2.3.4
* @version 3.1.9
* @since 1.0.0
* @todo [later] rethink `$product_id` (and search all code for `get_the_ID()`)
* @todo [maybe] min_profit
Expand All @@ -78,18 +78,35 @@ function add_cost_input() {
}
$product_id = get_the_ID();
if ( apply_filters( 'alg_wc_cog_add_cost_input_validation', true, $product_id ) ) {
$label_from_to = $this->get_cost_input_label_placeholders( $product_id );
woocommerce_wp_text_input( array(
'id' => '_alg_wc_cog_cost',
'value' => wc_format_localized_price( alg_wc_cog()->core->products->get_product_cost( $product_id ) ),
'data_type' => 'price',
'label' => str_replace( '%currency_symbol%', alg_wc_cog()->core->get_default_shop_currency_symbol(), $this->cost_field_template ),
'label' => str_replace( array_keys( $label_from_to ), $label_from_to, $this->cost_field_template ),
'description' => sprintf( __( 'Profit: %s', 'cost-of-goods-for-woocommerce' ),
( '' != ( $profit = alg_wc_cog()->core->products->get_product_profit_html( $product_id, alg_wc_cog()->core->products->product_profit_html_template ) ) ? $profit : __( 'N/A', 'cost-of-goods-for-woocommerce' ) ) ),
) );
}
do_action( 'alg_wc_cog_cost_input', $product_id );
}

/**
* get_cost_input_label_placeholders.
*
* @version 3.1.9
* @since 3.1.9
*
* @param $product_id
*
* @return mixed|null
*/
function get_cost_input_label_placeholders( $product_id = null ) {
return apply_filters( 'alg_wc_cog_cost_input_label_placeholders', array(
'%currency_symbol%' => alg_wc_cog()->core->get_default_shop_currency_symbol()
), $product_id );
}

/**
* add_cost_input_variable.
*
Expand Down
6 changes: 3 additions & 3 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.1.6
* @version 3.1.9
* @since 2.1.0
* @author WPFactory
*/
Expand Down Expand Up @@ -1243,7 +1243,7 @@ function get_shipping_total_for_percentage_fees( $order ) {
/**
* update_order_items_costs.
*
* @version 3.1.2
* @version 3.1.9
* @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 @@ -1328,7 +1328,7 @@ function update_order_items_costs( $args ) {
if ( $is_new_order ) {
if ( ! $is_no_costs_only || '' === wc_get_order_item_meta( $item_id, '_alg_wc_cog_item_cost' ) ) {
$product_id = ( ! empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'] );
$cost = apply_filters( 'alg_wc_cog_order_item_cost', alg_wc_cog()->core->products->get_product_cost( $product_id ), $product_id );
$cost = apply_filters( 'alg_wc_cog_order_item_cost', alg_wc_cog()->core->products->get_product_cost( $product_id ), $product_id, $item_id, $item );
$do_update = ( 0 !== $cost );
} else {
$do_update = false;
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.1.8';
public $version = '3.1.9';

/**
* @since 1.0.0
Expand Down
35 changes: 32 additions & 3 deletions includes/settings/class-alg-wc-cog-settings-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Compatibility Settings.
*
* @version 2.8.7
* @version 3.1.9
* @since 2.4.6
* @author WPFactory
*/
Expand Down Expand Up @@ -36,7 +36,7 @@ function __construct() {
/**
* get_settings.
*
* @version 2.8.7
* @version 3.1.9
* @since 2.4.6
*/
function get_settings() {
Expand Down Expand Up @@ -280,6 +280,34 @@ function get_settings() {
'id' => 'alg_wc_cog_compatibility_wc_food_options',
),
);
$wc_measurement_price_calculator_opts = array(
array(
'title' => __( 'WooCommerce Measurement Price Calculator', 'cost-of-goods-for-woocommerce' ),
'type' => 'title',
'desc' => sprintf( __( 'Compatibility with %s plugin.', 'cost-of-goods-for-woocommerce' ), '<a href="https://woo.com/document/measurement-price-calculator/" target="_blank">' . __( 'WooCommerce Measurement Price Calculator', 'cost-of-goods-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_cog_compatibility_wc_measurement_price_calc_options',
),
array(
'title' => __( 'Cost', 'cost-of-goods-for-woocommerce' ),
'desc' => __( 'Adjust the cost of goods sold according to the product measurement', 'cost-of-goods-for-woocommerce' ),
'id' => 'alg_wc_cog_comp_wcmpc_adjust_cost_by_measure',
'default' => 'no',
'type' => 'checkbox',
'custom_attributes' => apply_filters( 'alg_wc_cog_settings', array( 'disabled' => 'disabled' ) ),
),
array(
'title' => __( 'Cost field label placeholder', 'cost-of-goods-for-woocommerce' ),
'desc' => sprintf(__( 'Add the placeholder %s to the %s option', 'cost-of-goods-for-woocommerce' ), '<code>%measurement_unit%</code>','<a href="'.admin_url('admin.php?page=wc-settings&tab=alg_wc_cost_of_goods').'">'.__('cost field label').'</a>'),
'id' => 'alg_wc_cog_comp_wcmpc_add_measurement_unit_placeholder_to_cost_label',
'default' => 'no',
'type' => 'checkbox',
'custom_attributes' => apply_filters( 'alg_wc_cog_settings', array( 'disabled' => 'disabled' ) ),
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_cog_compatibility_wc_measurement_price_calc_options',
),
);
return array_merge(
$compatibility_opts,
$curcy_multicurrency_opts,
Expand All @@ -288,7 +316,8 @@ function get_settings() {
$wp_all_import_opts,
$wpc_product_bundle_opts,
$atum_opts,
$wc_food_opts
$wc_food_opts,
$wc_measurement_price_calculator_opts
);
}

Expand Down
22 changes: 13 additions & 9 deletions includes/settings/class-alg-wc-cog-settings-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Products Section Settings.
*
* @version 3.1.7
* @version 3.1.9
* @since 1.7.0
* @author WPFactory
*/
Expand All @@ -28,7 +28,7 @@ function __construct() {
/**
* get_settings.
*
* @version 3.1.7
* @version 3.1.9
* @since 1.7.0
* @todo [later] Cost field label: use in quick and bulk edit
* @todo [later] `alg_wc_cog_products_add_stock`: better description
Expand Down Expand Up @@ -89,13 +89,17 @@ function get_settings() {
'id' => 'alg_wc_cog_cost_field_options',
),
array(
'title' => __( 'Cost field label', 'cost-of-goods-for-woocommerce' ),
'desc' => sprintf( __( 'Available placeholders: %s.', 'cost-of-goods-for-woocommerce' ),
'<code>' . implode( '</code>, <code>', array( '%currency_symbol%' ) ) . '</code>' ),
'desc_tip' => __( 'Customizes the cost field input label added to admin product pages.', 'cost-of-goods-for-woocommerce' ),
'id' => 'alg_wc_cog_product_cost_field_template',
'default' => sprintf( __( 'Cost (excl. tax) (%s)', 'cost-of-goods-for-woocommerce' ), '%currency_symbol%' ),
'type' => 'text',
'title' => __( 'Cost field label', 'cost-of-goods-for-woocommerce' ),
'desc' => __( 'Placeholders:', 'cost-of-goods-for-woocommerce' ) . ' ' . alg_wc_cog_array_to_string(
alg_wc_cog()->core->cost_inputs->get_cost_input_label_placeholders( null ), array(
'item_template' => '<code>{key}</code>',
'glue' => ','
)
) . '.',
'desc_tip' => __( 'Customizes the cost field input label added to admin product pages.', 'cost-of-goods-for-woocommerce' ),
'id' => 'alg_wc_cog_product_cost_field_template',
'default' => sprintf( __( 'Cost (excl. tax) (%s)', 'cost-of-goods-for-woocommerce' ), '%currency_symbol%' ),
'type' => 'text',
'wpfse_data' => array(
'description' => '{desc_tip}'
),
Expand Down
4 changes: 2 additions & 2 deletions includes/settings/class-alg-wc-cog-settings-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function get_settings() {
array(
'title' => '[alg_wc_cog_product_profit]',
'desc' => __( 'Displays the product profit', 'cost-of-goods-for-woocommerce' ),
'desc_tip' => 'Params: <br />' . alg_wc_cog_array_to_string( array(
'desc_tip' => __( 'Params:', 'cost-of-goods-for-woocommerce' ) . '' . '<br />' . alg_wc_cog_array_to_string( array(
'product_id' => __( 'Product ID.', 'cost-of-goods-for-woocommerce' ) . ' ' . __( 'If empty, will try to get the current product id.', 'cost-of-goods-for-woocommerce' ),
'profit_template' => __( 'Profit template.', 'cost-of-goods-for-woocommerce' ) . ' ' . __( 'Default:', 'cost-of-goods-for-woocommerce' ) . ' <code>' . _wp_specialchars( get_option( 'alg_wc_cog_product_profit_html_template', '%profit% (%profit_percent%)' ) ) . '</code>.',
'html_template' => __( 'HTML template.', 'cost-of-goods-for-woocommerce' ) . ' ' . __( 'Default:', 'cost-of-goods-for-woocommerce' ) . ' <code>' . _wp_specialchars( '<span class="alg-wc-cog-product-profit">{content}</span>' ) . '</code>.',
Expand All @@ -74,7 +74,7 @@ function get_settings() {
array(
'title' => '[alg_wc_cog_product_cost]',
'desc' => __( 'Displays the product cost', 'cost-of-goods-for-woocommerce' ),
'desc_tip' => 'Params: <br />' . alg_wc_cog_array_to_string( array(
'desc_tip' => __( 'Params:', 'cost-of-goods-for-woocommerce' ) . '' . '<br />' . alg_wc_cog_array_to_string( array(
'product_id' => __( 'Product ID.', 'cost-of-goods-for-woocommerce' ) . ' ' . __( 'If empty, will try to get the current product id.', 'cost-of-goods-for-woocommerce' ),
'html_template' => __( 'HTML template.', 'cost-of-goods-for-woocommerce' ) . ' ' . __( 'Default:', 'cost-of-goods-for-woocommerce' ) . ' <code>' . _wp_specialchars( '<span class="alg-wc-cog-product-cost">{content}</span>' ) . '</code>.',
), array( 'item_template' => '<li><code>{key}</code> - {value}', 'glue' => '<br /></li>' ) ),
Expand Down
Loading

0 comments on commit 9cc0ab2

Please sign in to comment.