diff --git a/app/PriorPrice/Prices.php b/app/PriorPrice/Prices.php
index 8252a3f..f28b24e 100644
--- a/app/PriorPrice/Prices.php
+++ b/app/PriorPrice/Prices.php
@@ -104,13 +104,10 @@ public function lowest_price_html( \WC_Product $wc_product ): string {
$lowest = apply_filters( 'wc_price_history_lowest_price_html_raw_value_taxed', $lowest, $wc_product );
if ( (float) $lowest <= 0 ) {
- return '';
+ return $this->handle_old_history( $wc_product, $days_number );
}
- $lowest_html = '
%s
';
- $lowest_template = str_replace( [ '{price}', '{days}' ], [ $this->display_price_value_html( $lowest ), $days_number ], $this->settings_data->get_display_text() );
-
- return sprintf( $lowest_html, $lowest_template );
+ return $this->display_from_template( $lowest, $days_number );
}
/**
@@ -205,4 +202,57 @@ private function is_main_product( \WC_Product $wc_product ) : bool {
return isset( $wp_query->queried_object_id ) && $wp_query->queried_object_id === $wc_product->get_id();
}
+
+ /**
+ * Handle history older than x days (returned price is 0).
+ *
+ * @since 1.9.0
+ *
+ * @param \WC_Product $wc_product WC Product.
+ * @param int $days_number Days number.
+ *
+ * @return string
+ */
+ private function handle_old_history( \WC_Product $wc_product, int $days_number ) : string {
+
+ $old_history = $this->settings_data->get_old_history();
+
+ if ( $old_history === 'hide' ) {
+ return '';
+ }
+
+ if ( $old_history === 'current_price' ) {
+ return $this->display_from_template( (float) $wc_product->get_price(), $days_number );
+ }
+
+ $old_history_custom_text = $this->settings_data->get_old_history_custom_text();
+
+ $old_history_custom_text = str_replace(
+ [ '{price}', '{days}' ],
+ [ $this->display_price_value_html( (float) $wc_product->get_price() ), $days_number ],
+ $old_history_custom_text
+ );
+
+ return '' . $old_history_custom_text . '
';
+ }
+
+ /**
+ * Display full price HTML from template.
+ *
+ * @since 1.9.0
+ *
+ * @param float $lowest Lowest price.
+ * @param int $days_number Days number.
+ *
+ * @return string
+ */
+ private function display_from_template( float $lowest, int $days_number ) : string {
+
+ $display_text = $this->settings_data->get_display_text();
+
+ $display_text = str_replace( '{price}', $this->display_price_value_html( $lowest ), $display_text );
+ $display_text = str_replace( '{days}', (string) $days_number, $display_text );
+
+ return '' . $display_text . '
';
+ }
}
diff --git a/app/PriorPrice/SettingsData.php b/app/PriorPrice/SettingsData.php
index e2412fe..9c135ee 100644
--- a/app/PriorPrice/SettingsData.php
+++ b/app/PriorPrice/SettingsData.php
@@ -48,6 +48,12 @@ public function set_defaults() : void {
$update = true;
}
+ if ( ! isset( $settings['old_history'] ) ) {
+ $settings['old_history'] = 'custom_text'; // 'hide', 'current_price', 'custom_text'
+ $settings['old_history_custom_text'] = esc_html__( 'Price in the last {days} days is the same as current', 'wc-price-history' );
+ $update = true;
+ }
+
if ( $update ) {
update_option( 'wc_price_history_settings', $settings );
}
@@ -151,4 +157,36 @@ public function get_display_line_through() : bool {
}
return (bool) $settings['display_line_through'];
}
+
+ /**
+ * Get old history setting.
+ *
+ * @since 1.9.0
+ *
+ * @return string
+ */
+ public function get_old_history() : string {
+
+ $settings = get_option( 'wc_price_history_settings' );
+ if ( ! isset( $settings['old_history'] ) ) {
+ return 'hide';
+ }
+ return $settings['old_history'];
+ }
+
+ /**
+ * Get old history custom text setting.
+ *
+ * @since 1.9.0
+ *
+ * @return string
+ */
+ public function get_old_history_custom_text() : string {
+
+ $settings = get_option( 'wc_price_history_settings' );
+ if ( ! isset( $settings['old_history_custom_text'] ) ) {
+ return esc_html__( 'Price in the last {days} days is the same as current', 'wc-price-history' );
+ }
+ return esc_html( $settings['old_history_custom_text'] );
+ }
}
diff --git a/app/PriorPrice/SettingsPage.php b/app/PriorPrice/SettingsPage.php
index 2804f4f..23c5d83 100644
--- a/app/PriorPrice/SettingsPage.php
+++ b/app/PriorPrice/SettingsPage.php
@@ -217,7 +217,7 @@ class="wc-history-price-display-when-input"
value="sale_start_inclusive"
/>
-
+
@@ -248,6 +248,7 @@ class="wc-history-price-display-when-input"
@@ -263,12 +264,13 @@ class="wc-history-price-display-when-input"
|
+
+
+ ' . $settings['days_number'] . ''
+ );
+ ?>
+ |
+
+
+ |
+
|
diff --git a/assets/css/admin.css b/assets/css/admin.css
index 0a9bc75..d4fe385 100644
--- a/assets/css/admin.css
+++ b/assets/css/admin.css
@@ -1,4 +1,19 @@
+.wc-price-history-wide-field {
+ width: 90%;
+}
+
+.wc-price-history-old-history-custom-text-p {
+ opacity: 1;
+ height: 100%;
+ overflow: hidden;
+ transition: opacity 0.5s, height 0.5s;
+}
+
+.wc-price-history-old-history-custom-text-p.hidden-fade {
+ opacity: 0;
+ height: 0;
+}
.wc-history-price-admin__left {
float: left;
diff --git a/assets/js/admin.js b/assets/js/admin.js
index ad21a74..6d06389 100644
--- a/assets/js/admin.js
+++ b/assets/js/admin.js
@@ -1,2 +1,27 @@
jQuery(document).ready(function($) {
+
+ // Toggle the custom text field when the custom text radio button is selected.
+ $( '#wc-price-history-old-history-fieldset input' ).on(
+ 'change',
+ function() {
+ if ( $( '#wc-price-history-old-history-fieldset input:checked' ).val() == 'custom_text' ) {
+ $( '.wc-price-history-old-history-custom-text-p' ).removeClass( 'hidden-fade' );
+ } else {
+ $( '.wc-price-history-old-history-custom-text-p' ).addClass( 'hidden-fade' );
+ }
+ }
+ );
+
+ // There are tesxts like "What to do when price history is older than {days-set} days" on the page's HTML code.
+ // copy value from input field #wc-price-history-days-number to every place on page where is {days-set} placeholder in pages HTML (replace it).
+ $( '#wc-price-history-days-number' ).on(
+ 'input',
+ function() {
+ $( '.wc-price-history-days-set' ).each(
+ function() {
+ $( this ).text( $( '#wc-price-history-days-number' ).val() );
+ }
+ );
+ }
+ );
});
diff --git a/languages/wc-price-history.pot b/languages/wc-price-history.pot
index 24b9e13..a26f48e 100644
--- a/languages/wc-price-history.pot
+++ b/languages/wc-price-history.pot
@@ -2,14 +2,14 @@
# This file is distributed under the same license as the WC Price History plugin.
msgid ""
msgstr ""
-"Project-Id-Version: WC Price History 1.7.1\n"
+"Project-Id-Version: WC Price History 1.9.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-price-history\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-"POT-Creation-Date: 2023-02-19T17:13:01+01:00\n"
+"POT-Creation-Date: 2023-12-16T13:38:22+01:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.6.0\n"
"X-Domain: wc-price-history\n"
@@ -23,13 +23,17 @@ msgid "https://github.com/kkarpieszuk/wc-price-history"
msgstr ""
#. Description of the plugin
-msgid "Track WooCommerce© Products prior prices history and display the lowest price in the last 30 days. This plugin allows your WC shop to be compliant with European Commission Directive 98/6/EC Article 6a which specifies price reduction announcement policy."
+msgid "Track WooCommerce Products prior prices history and display the lowest price in the last 30 days (fully configurable). This plugin allows your WC shop to be compliant with European Commission Directive 98/6/EC Article 6a which specifies price reduction announcement policy."
msgstr ""
#. Author of the plugin
msgid "Konrad Karpieszuk"
msgstr ""
+#. Author URI of the plugin
+msgid "https://wpzlecenia.pl"
+msgstr ""
+
#. translators: %d product id, %s link to product edit screen.
#: app/PriorPrice/HistoryStorage.php:71
msgid "Product #%1$d is on sale but has no sale start date. Please edit this product and set starting date for sale: %2$s"
@@ -42,12 +46,19 @@ msgstr ""
#. translators: Do not translate {price}, it is template slug!
#: app/PriorPrice/SettingsData.php:47
-#: app/PriorPrice/SettingsPage.php:271
+#: app/PriorPrice/SettingsPage.php:273
msgid "30-day low: {price}"
msgstr ""
+#. translators: Do not translate {days}, it is template slug!
+#: app/PriorPrice/SettingsData.php:53
+#: app/PriorPrice/SettingsData.php:188
+#: app/PriorPrice/SettingsPage.php:343
+msgid "Price in the last {days} days is the same as current"
+msgstr ""
+
#. translators: %s - the lowest price in the last 30 days.
-#: app/PriorPrice/SettingsData.php:132
+#: app/PriorPrice/SettingsData.php:138
msgid "30-day low: %s"
msgstr ""
@@ -126,7 +137,7 @@ msgid "Day before product went on sale (excludes promotional price)"
msgstr ""
#: app/PriorPrice/SettingsPage.php:220
-msgid "Day when product product went on sale (includes promotional price)"
+msgid "Day when product went on sale (includes promotional price)"
msgstr ""
#: app/PriorPrice/SettingsPage.php:224
@@ -154,55 +165,81 @@ msgstr ""
msgid "Number of days to use when counting minimal price:"
msgstr ""
-#: app/PriorPrice/SettingsPage.php:253
+#: app/PriorPrice/SettingsPage.php:254
msgid "days"
msgstr ""
-#: app/PriorPrice/SettingsPage.php:256
+#: app/PriorPrice/SettingsPage.php:257
msgid "Omnibus: European Union Guidance requires displaying lowest price from the last 30 days."
msgstr ""
-#: app/PriorPrice/SettingsPage.php:262
+#: app/PriorPrice/SettingsPage.php:263
msgid "Minimal price text:"
msgstr ""
#. translators: Do not translate {price} and {days}, those are template slugs!
-#: app/PriorPrice/SettingsPage.php:277
+#: app/PriorPrice/SettingsPage.php:279
msgid "Use placeholder {price} to display price and {days} to display number of days."
msgstr ""
-#: app/PriorPrice/SettingsPage.php:283
+#. translators: %s: {days-set} template slug
+#: app/PriorPrice/SettingsPage.php:289
+msgid "What to do when price history is older than %s days:"
+msgstr ""
+
+#. translators: Do not translate {days-set}, it is template slug!
+#: app/PriorPrice/SettingsPage.php:300
+msgid "It could happen that the last change of price was more than %s days ago. In that case you can choose to hide minimal price, display current price or display custom text."
+msgstr ""
+
+#: app/PriorPrice/SettingsPage.php:313
+msgid "Hide minimal price"
+msgstr ""
+
+#: app/PriorPrice/SettingsPage.php:323
+msgid "Display current price"
+msgstr ""
+
+#: app/PriorPrice/SettingsPage.php:333
+msgid "Display custom text"
+msgstr ""
+
+#: app/PriorPrice/SettingsPage.php:348
+msgid "If you choose to display custom text, use placeholder {days} to display number of days and {price} to display current price."
+msgstr ""
+
+#: app/PriorPrice/SettingsPage.php:354
msgid "When displaying minimal price:"
msgstr ""
-#: app/PriorPrice/SettingsPage.php:294
+#: app/PriorPrice/SettingsPage.php:365
msgid "Apply line-through on the price"
msgstr ""
-#: app/PriorPrice/SettingsPage.php:298
+#: app/PriorPrice/SettingsPage.php:369
msgid "If checked, price will be displayed with line-through on it."
msgstr ""
-#: app/PriorPrice/SettingsPage.php:309
+#: app/PriorPrice/SettingsPage.php:380
msgid "Read the EU legal acts:"
msgstr ""
-#: app/PriorPrice/SettingsPage.php:311
+#: app/PriorPrice/SettingsPage.php:382
msgid "Guidance on the Price Indication Directive (2021)"
msgstr ""
-#: app/PriorPrice/SettingsPage.php:314
+#: app/PriorPrice/SettingsPage.php:385
msgid "Support"
msgstr ""
-#: app/PriorPrice/SettingsPage.php:317
+#: app/PriorPrice/SettingsPage.php:388
msgid "If you have any questions, please contact me at plugin support forum."
msgstr ""
-#: app/PriorPrice/SettingsPage.php:321
+#: app/PriorPrice/SettingsPage.php:392
msgid "Please rate the plugin! "
msgstr ""
-#: plugin.php:25
+#: plugin.php:26
msgid "WooCommerce Price History plugin requires WooCommerce to be installed and active."
msgstr ""
diff --git a/plugin.php b/plugin.php
index e01d1a4..cd7da60 100644
--- a/plugin.php
+++ b/plugin.php
@@ -1,9 +1,10 @@
`Price History` screen. You can confi
↪ How to count minimal price (the minimal from the moment product went on sale to 30 days before that moment or the minimal price from today to 30 days ago)
↪ How many days take into account when calculating minimal price (30 days by default)
↪ How to display the price history information
+↪ What to do if the price didn't change in the last N days (hide price information / display current price / display custom text)
At the configuration screen you will find additional information how to configure the plugin to be compliant with Omnibus directive (European Commission Directive 98/6/EC Article 6a) and link to legal acts.
@@ -112,6 +113,9 @@ Please submit the [GitHub issue](https://github.com/kkarpieszuk/wc-price-history
== Changelog ==
+= 1.9.0 =
+* New: Allow to decide what to display in case there was no price change in the tracked history span. (#77)
+
= 1.8.0 =
* New: Basic compatibility with dynamic pricing plugins.
* New: Displayed HTML is translatable with WPML and Polylang.
|