Skip to content

Commit

Permalink
v3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Oct 19, 2023
1 parent 2acf2e5 commit 666265f
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 15 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.0.9
Version: 3.1.0
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Expand Down
63 changes: 60 additions & 3 deletions includes/class-alg-wc-cog-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Products Class.
*
* @version 2.9.6
* @version 3.1.0
* @since 2.1.0
* @author WPFactory
*/
Expand Down Expand Up @@ -86,11 +86,10 @@ function get_options() {
/**
* add_hooks.
*
* @version 2.8.2
* @version 3.1.0
* @since 2.1.0
*/
function add_hooks() {

// Products columns
if ( $this->is_column_profit || $this->is_column_cost ) {
add_filter( 'manage_edit-product_columns', array( $this, 'add_product_columns' ) );
Expand All @@ -116,6 +115,64 @@ function add_hooks() {
add_action( 'updated_post_meta', array( $this, 'save_profit_on_postmeta' ), 10, 4 );
add_action( 'added_post_meta', array( $this, 'save_profit_on_postmeta' ), 10, 4 );
add_action( 'deleted_post_meta', array( $this, 'save_profit_on_postmeta' ), 10, 4 );
// Shortcodes.
add_shortcode( 'alg_wc_cog_product_profit', array( $this, 'sc_alg_wc_cog_product_profit' ) );
add_shortcode( 'alg_wc_cog_product_cost', array( $this, 'sc_alg_wc_cog_product_cost' ) );
}

/**
* alg_wc_cog_product_cost.
*
* @version 3.1.0
* @since 3.1.0
*
* @param $atts
*
* @return string
*/
function sc_alg_wc_cog_product_cost( $atts ) {
if ( 'no' === get_option( 'alg_wc_cog_shortcode_product_cost', 'no' ) ) {
return '[alg_wc_cog_product_cost]';
}
$atts = shortcode_atts( array(
'product_id' => get_the_ID(),
'html_template' => '<span class="alg-wc-cog-product-cost">{content}</span>',
), $atts, 'alg_wc_cog_product_cost' );
$product_id = intval( $atts['product_id'] );
$html_template = $atts['html_template'];
$array_from_to = array(
'{content}' => $this->get_product_cost_html( $product_id )
);

return str_replace( array_keys( $array_from_to ), $array_from_to, $html_template );
}

/**
* @version 3.1.0
* @since 3.1.0
*
* @param $atts
*
* @return string
*/
function sc_alg_wc_cog_product_profit( $atts ) {
if ( 'no' === get_option( 'alg_wc_cog_shortcode_product_profit', 'no' ) ) {
return '[alg_wc_cog_product_profit]';
}
$atts = shortcode_atts( array(
'product_id' => get_the_ID(),
'profit_template' => ! is_null( $this->product_profit_html_template ) ? $this->product_profit_html_template : get_option( 'alg_wc_cog_product_profit_html_template', '%profit% (%profit_percent%)' ),
'html_template' => '<span class="alg-wc-cog-product-profit">{content}</span>',
), $atts, 'alg_wc_cog_product_profit' );

$product_id = intval( $atts['product_id'] );
$profit_template = sanitize_text_field( $atts['profit_template'] );
$html_template = $atts['html_template'];
$array_from_to = array(
'{content}' => $this->get_product_profit_html( $product_id, $profit_template ),
);

return str_replace( array_keys( $array_from_to ), $array_from_to, $html_template );
}

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

/**
* @since 1.0.0
Expand Down
42 changes: 39 additions & 3 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 2.9.3
* @version 3.1.0
* @since 1.7.0
* @author WPFactory
*/
Expand All @@ -28,7 +28,7 @@ function __construct() {
/**
* get_settings.
*
* @version 2.9.3
* @version 3.1.0
* @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 @@ -390,14 +390,50 @@ function get_settings() {
),
);

$shortcode_opts = array(
array(
'title' => __( 'Shortcodes', 'cost-of-goods-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_cog_product_shortcode_opts',
),
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(
'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>.',
), array( 'item_template' => '<li><code>{key}</code> - {value}', 'glue' => '<br /></li>' ) ),
'id' => 'alg_wc_cog_shortcode_product_profit',
'default' => 'no',
'type' => 'checkbox',
),
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(
'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>' ) ),
'id' => 'alg_wc_cog_shortcode_product_cost',
'default' => 'no',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_cog_product_shortcode_opts',
),
);

return array_merge(
$product_settings,
$cost_input_settings,
$product_columns_settings,
$cost_archive_opts,
$add_stock_settings,
$product_quick_bulk_edit_settings,
$cost_sanitization_opts
$cost_sanitization_opts,
$shortcode_opts
);
}

Expand Down
49 changes: 43 additions & 6 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 3.0.9\n"
"Project-Id-Version: cost-of-goods-for-woocommerce 3.1.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-10-19T03:29:02+02:00\n"
"POT-Creation-Date: 2023-10-19T20:16:01+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 @@ -79,10 +79,10 @@ msgstr ""
#: includes/class-alg-wc-cog-orders.php:787
#: includes/class-alg-wc-cog-products-add-stock.php:124
#: includes/class-alg-wc-cog-products-add-stock.php:141
#: includes/class-alg-wc-cog-products.php:248
#: includes/class-alg-wc-cog-products.php:259
#: includes/class-alg-wc-cog-products.php:270
#: includes/class-alg-wc-cog-products.php:305
#: includes/class-alg-wc-cog-products.php:316
#: includes/class-alg-wc-cog-products.php:327
#: includes/class-alg-wc-cog-products.php:384
#: includes/pro/class-alg-wc-cog-pro.php:457
#: includes/pro/class-alg-wc-cog-pro.php:814
#: includes/pro/reports/class-wc-report-alg-cog-stock.php:121
Expand All @@ -103,7 +103,7 @@ msgstr ""
#: includes/class-alg-wc-cog-orders-meta-boxes.php:149
#: includes/class-alg-wc-cog-orders.php:678
#: includes/class-alg-wc-cog-orders.php:797
#: includes/class-alg-wc-cog-products.php:330
#: includes/class-alg-wc-cog-products.php:387
#: includes/pro/reports/class-wc-report-alg-cog-stock.php:123
#: includes/tools/class-alg-wc-cog-bulk-edit-tool.php:391
#: includes/analytics/build/index.js:1
Expand Down Expand Up @@ -1967,6 +1967,43 @@ msgstr ""
msgid "None"
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-products.php:395
msgid "Shortcodes"
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-products.php:401
msgid "Displays the product profit"
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-products.php:403
#: includes/settings/class-alg-wc-cog-settings-products.php:415
msgid "Product ID."
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-products.php:403
#: includes/settings/class-alg-wc-cog-settings-products.php:415
msgid "If empty, will try to get the current product id."
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-products.php:404
msgid "Profit template."
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-products.php:404
#: includes/settings/class-alg-wc-cog-settings-products.php:405
#: includes/settings/class-alg-wc-cog-settings-products.php:416
msgid "Default:"
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-products.php:405
#: includes/settings/class-alg-wc-cog-settings-products.php:416
msgid "HTML template."
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-products.php:413
msgid "Displays the product cost"
msgstr ""

#: includes/settings/class-alg-wc-cog-settings-shipping-classes.php:24
msgid "Shipping classes"
msgstr ""
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: wpcodefactory, omardabbas, karzin, anbinder, algoritmika, kousikmu
Tags: woocommerce, cost, cost of goods, cog, cost of goods sold, cogs, woo commerce
Requires at least: 4.4
Tested up to: 6.3
Stable tag: 3.0.9
Stable tag: 3.1.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,10 @@ And then you can follow these steps:

== Changelog ==

= 3.1.0 - 19/10/2023 =
* Dev - Shortcodes - New shortcode: `[alg_wc_cog_product_profit]`.
* Dev - Shortcodes - New shortcode: `[alg_wc_cog_product_cost]`.

= 3.0.9 - 18/10/2023 =
* Fix - Analytics - Cost and Profit columns are not present in Products CSV sent by email.

Expand Down

0 comments on commit 666265f

Please sign in to comment.