origin push

This commit is contained in:
khaccount 2025-04-06 08:34:48 +02:00
parent a0eee7c14a
commit 7f6f3538ce
6777 changed files with 349174 additions and 250960 deletions

View file

@ -0,0 +1,53 @@
<?php
/*
Plugin Name: Disable Responsive Images Complete
Plugin URI: https://perishablepress.com/disable-wordpress-responsive-images/
Description: Completely disables WP responsive images
Tags: responsive, images, responsive images, disable, srcset
Author: Jeff Starr
Author URI: https://plugin-planet.com/
Donate link: https://monzillamedia.com/donate.html
Contributors: specialk
Requires at least: 4.7
Tested up to: 6.8
Stable tag: 2.6.5
Version: 2.6.5
Requires PHP: 5.6.20
License: GPL v2 or later
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
with this program. If not, visit: https://www.gnu.org/licenses/
Copyright 2025 Monzilla Media. All rights reserved.
*/
if (!defined('ABSPATH')) exit;
// disable srcset on frontend
function disable_wp_responsive_images() {
return 1;
}
add_filter('max_srcset_image_width', 'disable_wp_responsive_images');
// disable 768px image generation
function disable_wp_responsive_image_sizes($sizes) {
unset($sizes['medium_large']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'disable_wp_responsive_image_sizes');

View file

@ -0,0 +1,148 @@
=== Disable Responsive Images Complete ===
Plugin Name: Disable Responsive Images Complete
Plugin URI: https://perishablepress.com/disable-wordpress-responsive-images/
Description: Completely disables WP responsive images
Tags: responsive, images, responsive images, disable, srcset
Author: Jeff Starr
Author URI: https://plugin-planet.com/
Donate link: https://monzillamedia.com/donate.html
Contributors: specialk
Requires at least: 4.7
Tested up to: 6.8
Stable tag: 2.6.5
Version: 2.6.5
Requires PHP: 5.6.20
License: GPL v2 or later
Completely disables WP responsive images.
== Description ==
This plugin completely disables WP responsive-image feature that was introduced in version 4.4. It is meant for people who know what they are doing and want to use their own responsive-image techniques.
**Features**
* Disables responsive images on the front-end
* Disables generation of `medium_large` 768px image size
* Completely plug-and-play, no configuration required
* Works perfectly with or without Gutenberg block editor
* Uses the WP API to disable responsive images
* Clean, lightweight code, a real pleasure
Why would anyone want to do this? Check out the FAQs below for all sorts of good reasons.
Check out [Disable WordPress Responsive Images](https://perishablepress.com/disable-wordpress-responsive-images/) at Perishable Press for more information about how this plugin works, etc.
> __Related:__ Free plugin to control which image sizes are generated by WordPress, check out [Disable Media Sizes](https://wordpress.org/plugins/disable-media-sizes/).
**Privacy**
This plugin does not collect or store any user data. It does not set any cookies, and it does not connect to any third-party locations. Thus, this plugin does not affect user privacy in any way.
Disable Responsive Images Complete is developed and maintained by [Jeff Starr](https://x.com/perishable), 15-year [WordPress developer](https://plugin-planet.com/) and [book author](https://books.perishablepress.com/).
**Support development**
I develop and maintain this free plugin with love for the WordPress community. To show support, you can [make a donation](https://monzillamedia.com/donate.html) or purchase one of my books:
* [The Tao of WordPress](https://wp-tao.com/)
* [Digging into WordPress](https://digwp.com/)
* [.htaccess made easy](https://htaccessbook.com/)
* [WordPress Themes In Depth](https://wp-tao.com/wordpress-themes-book/)
* [Wizard's SQL Recipes for WordPress](https://books.perishablepress.com/downloads/wizards-collection-sql-recipes-wordpress/)
And/or purchase one of my premium WordPress plugins:
* [BBQ Pro](https://plugin-planet.com/bbq-pro/) - Super fast WordPress firewall
* [Blackhole Pro](https://plugin-planet.com/blackhole-pro/) - Automatically block bad bots
* [Banhammer Pro](https://plugin-planet.com/banhammer-pro/) - Monitor traffic and ban the bad guys
* [GA Google Analytics Pro](https://plugin-planet.com/ga-google-analytics-pro/) - Connect WordPress to Google Analytics
* [Head Meta Pro](https://plugin-planet.com/head-meta-pro/) - Ultimate Meta Tags for WordPress
* [Simple Ajax Chat Pro](https://plugin-planet.com/simple-ajax-chat-pro/) - Unlimited chat rooms
* [USP Pro](https://plugin-planet.com/usp-pro/) - Unlimited front-end forms
Links, tweets and likes also appreciated. Thank you! :)
== Installation ==
**How to Install**
1. Upload the plugin to your blog and activate
2. Visit the plugin settings to configure options
[More info on installing WP plugins](https://wordpress.org/support/article/managing-plugins/#installing-plugins)
**Like the plugin?**
If you like Disable Responsive Images, please take a moment to [give a 5-star rating](https://wordpress.org/support/plugin/disable-responsive-images-complete/reviews/?rate=5#new-post). It helps to keep development and support going strong. Thank you!
== Upgrade Notice ==
To upgrade this plugin, remove the old version and replace with the new version. Or just click "Update" from the Plugins screen and let WordPress do it for you automatically.
Note: this plugin does not add anything to your WP database.
== Frequently Asked Questions ==
**Where are the screenshots?**
This plugin works behind the scenes with no settings required. So there are no screenshots to show!
**Does this work for WP Multisite?**
Yes, this plugin works great on Multisite.
**How does this plugin differ from the original Disable Responsive Images plugin?**
The difference is that this plugin also disables the extra 768px image copy from being generated for every image upload. So it saves server memory and other precious resources. Additionally, at the time this plugin was created, the original Disable Responsive Images plugin had not been updated in over 2 years.
**Why would I want to disable responsive images?**
This plugin is not "anti-responsiveness". In fact, quite the opposite. WP responsive-image feature locks users into prescribed methods, instead of leaving it open for users to create their own solution. With this plugin, users take back control in order to implement their own preferred responsive solutions. So it's actually "pro-responsiveness", as it frees designers and developers and encourages independent, innovative implementations.
For anyone still confused, here is a list of reasons why anyone would want to disable WP responsive images:
* Because not all sites want or need responsive images
* Because not all users want or need WordPress to do everything for them
* Because generalized solutions do not cater to 100% of users or scenarios
* Because there are many different ways to implement responsive images
* Because the WP method makes assumptions that may not hold true in every case
* Because some users want to implement their own responsive image solutions
* Because the WP method generates an additional mid-size image for every image upload (which can be wasteful and gobble up server memory and other resources)
Again, as explained on the homepage, this plugin is designed for people who _know what they are doing_ and want full control over how responsive images are handled on their WordPress-powered site.
**Got a question?**
Send any questions or feedback via my [contact form](https://plugin-planet.com/support/#contact)
== Changelog ==
If you like Disable Responsive Images, please take a moment to [give a 5-star rating](https://wordpress.org/support/plugin/disable-responsive-images-complete/reviews/?rate=5#new-post). It helps to keep development and support going strong. Thank you!
**2.6.5 (2025/03/20)**
* Tests on WordPress 6.8
Full changelog @ [https://plugin-planet.com/wp/changelog/disable-responsive-images-complete.txt](https://plugin-planet.com/wp/changelog/disable-responsive-images-complete.txt)

View file

@ -1,3 +1,8 @@
/**1.2.13 - 2025.02.21***/
- Fixed: Display correctly the expiration date of the download order item
- Updated: Responsive mobile
- Updated: Use the default template for the changed password email and the email of the changed email if the 9MAIL is not activated
/**1.2.12 - 2025.01.10***/
- Updated: VillaTheme support

View file

@ -1304,6 +1304,9 @@ input.form-control, select.form-control, .viwec-col-full.input {
.viwec-mobile-preview #body_content .viwec-responsive-min-width > table {
width: 300px;
}
.viwec-mobile-preview #body_content td.viwec-responsive {
display: inline-block !important;
}
.viwec-mobile-preview #body_content .viwec-responsive {
width: 100% !important;
}
@ -1318,6 +1321,10 @@ input.form-control, select.form-control, .viwec-col-full.input {
}
.viwec-mobile-preview #body_content .viwec-mobile-50 {
width: 50% !important;
display: inline-block !important;
}
.viwec-mobile-preview #body_content .viwec-mobile-50 .woocommerce-Price-amount {
margin-right: 1px;
}
.viwec-mobile-preview #body_content .viwec-center-on-mobile p {
text-align: center !important;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1604,6 +1604,9 @@ input.form-control, select.form-control, .viwec-col-full.input {
& .viwec-responsive-min-width > table {
width: 300px;
}
td.viwec-responsive {
display: inline-block !important;
}
.viwec-responsive {
width: 100% !important;
@ -1623,6 +1626,10 @@ input.form-control, select.form-control, .viwec-col-full.input {
.viwec-mobile-50 {
width: 50% !important;
display: inline-block !important;
.woocommerce-Price-amount{
margin-right: 1px;
}
}
.viwec-center-on-mobile p {

View file

@ -485,8 +485,12 @@ jQuery(document).ready(function ($) {
multiple: false
}).open().on('select', function (e) {
let uploadedImages = images.state().get('selection').first();
if (uploadedImages?.changed?.subtype === 'svg+xml'){
alert('Unfortunately, most email clients do not support SVG. Kindly use a different image.');
}else {
let selectedImages = uploadedImages.toJSON();
event.data.element.trigger('propertyChange', [`url(${selectedImages.url})`, this]);
}
})
}
},
@ -511,8 +515,12 @@ jQuery(document).ready(function ($) {
multiple: false
}).open().on('select', function (e) {
let uploadedImages = images.state().get('selection').first();
if (uploadedImages?.changed?.subtype === 'svg+xml'){
alert('Unfortunately, most email clients do not support SVG. Kindly use a different image.');
}else {
let selectedImages = uploadedImages.toJSON();
event.data.element.trigger('propertyChange', [selectedImages.url, this]);
}
});
}
},

View file

@ -539,7 +539,16 @@ jQuery(document).ready(function ($) {
},
hideRules(type) {
// Pro
let rules = $('#viwec-box-rule');
rules.show();
rules.find('.viwec-setting-row').show();
let args = viWecParams.hide_rule || '';
let list = args[type] || '';
if (!list) return;
if (list.length === 8) rules.hide();
for (let el of list) {
rules.find(`.viwec-setting-row[data-attr=${el}]`).hide();
}
},
hideElements(type) {

View file

@ -3,7 +3,7 @@
* Plugin Name: Email Template Customizer for WooCommerce
* Plugin URI: https://villatheme.com/extensions/woocommerce-email-template-customizer/
* Description: Customize your WooCommerce emails effortlessly. Drag and drop elements, edit layouts, and match your store's design without coding knowledge.
* Version: 1.2.12
* Version: 1.2.13
* Author: VillaTheme
* Author URI: https://villatheme.com
* License: GPL v2 or later
@ -14,7 +14,7 @@
* Requires at least: 5.0
* Tested up to: 6.7
* WC requires at least: 7.0
* WC tested up to: 9.5
* WC tested up to: 9.6
* Requires PHP: 7.0
* Requires Plugins: woocommerce
**/
@ -34,7 +34,7 @@ add_action( 'before_woocommerce_init', function () {
if ( is_plugin_active( 'woocommerce-email-template-customizer/woocommerce-email-template-customizer.php' ) ) {
return;
}
define( 'VIWEC_VER', '1.2.12' );
define( 'VIWEC_VER', '1.2.13' );
define( 'VIWEC_NAME', 'Email Template Customizer for WooCommerce' );
$plugin_url = plugin_dir_url( __FILE__ );
@ -73,7 +73,7 @@ if ( ! class_exists( 'Woo_Email_Template_Customizer' ) ) {
[
'slug' => 'woocommerce',
'name' => 'WooCommerce',
'file' => 'woocommerce/woocommerce.php',
'defined_version' => 'WC_VERSION',
'version' => $this->wc_version_require,
],
]

View file

@ -152,6 +152,10 @@ class Email_Builder {
'title' => esc_html__( 'Rules', 'viwec-email-template-customizer' ),
'func' => [ $this, 'email_rules_box' ]
],
'attachment' => [
'title' => esc_html__( 'Attachment files', 'viwec-email-template-customizer' ),
'func' => [ $this, 'email_attachment_box' ]
],
'testing' => [
'title' => esc_html__( 'Testing', 'viwec-email-template-customizer' ),
'func' => [ $this, 'email_testing_box' ]
@ -216,6 +220,15 @@ class Email_Builder {
VIWEC_TEMPLATES );
}
public function email_attachment_box( $post ) {
?>
<div>
<div class="viwec-setting-row" data-attr="attachment">
<?php viwec_get_pro_version() ?>
</div>
</div>
<?php
}
public function email_rules_box( $post ) {
$settings = get_post_meta( $post->ID, 'viwec_setting_rules', true );
$params = [

View file

@ -657,7 +657,7 @@ class Email_Render {
$html .= '</tr>';
}
$html = "<table align='{$align}' border='0' cellpadding='0' cellspacing='0' >$html</table>";
$html = "<table class='viwec-no-full-width-on-mobile' align='{$align}' border='0' cellpadding='0' cellspacing='0' >$html</table>";
echo wp_kses( $html, viwec_allowed_html() );
}
@ -1189,15 +1189,15 @@ class Email_Render {
foreach ( $downloads as $download ) {
if ( $pid == $download['product_id'] ) {
$href = esc_url( $download['download_url'] );
$display = esc_html( $download['download_name'] );
$display = wp_kses_post( $download['download_name'] );
$expires = '';
if ( ! empty( $download['access_expires'] ) ) {
$datetime = esc_attr( date_i18n( 'Y-m-d', strtotime( $download['access_expires'] ) ) );
$title = esc_attr( strtotime( $download['access_expires'] ) );
$display_time = esc_html( date_i18n( get_option( 'date_format' ), strtotime( $download['access_expires'] ) ) );
$expires = "- <time datetime='$datetime' title='$title'>$display_time</time>";
$expires = " <time datetime='$datetime' title='$title'>$display_time</time>";
}
printf( "<p><a href='%s'>%s</a> %s</p>", esc_url( $href ), esc_html( $display ), esc_html( $expires ) );
printf( "<p><a href='%s'>%s - %s</a></p>", esc_url( $href ), wp_kses_post( $display ), wp_kses_post( $expires ) );
}
}
}

View file

@ -47,6 +47,17 @@ class Email_Trigger {
add_action( 'viwec_email_template', array( $this, 'load_template' ), 10 );
add_action( 'woocommerce_email', array( $this, 'get_email_ids' ) );
add_filter( 'wp_new_user_notification_email', array( $this, 'replace_wp_new_user_email' ), 1, 3 );
add_filter( 'retrieve_password_title', array( $this, 'replace_wp_reset_password_title' ), 1, 3 );
if ( !class_exists( 'EmTmpl\EMTMPL_Email_Templates_Designer' ) && !class_exists( 'EmTmplF\WP_Email_Templates_Designer' ) ) {
add_filter( 'password_change_email', array( $this, 'replace_default_to_wp_email' ), 1, 1);
add_filter( 'email_change_email', array( $this, 'replace_default_to_wp_email' ), 1, 1);
}
$priority_retrieve_password_message = 1;
/*Compatible with paid-memberships-pro */
if ( function_exists( 'pmpro_gateways' ) ) {
$priority_retrieve_password_message = 11;
}
add_filter( 'retrieve_password_message', array( $this, 'replace_wp_reset_password_email' ), $priority_retrieve_password_message, 4 );
add_filter( 'woocommerce_email_styles', array( $this, 'remove_style' ), 99 );
add_filter( 'woocommerce_email_styles', array( $this, 'custom_css' ), 99999 );
@ -348,6 +359,23 @@ class Email_Trigger {
return $id;
}
public function replace_default_to_wp_email( $email) {
$this->template_id = $this->get_default_template();
if ( $this->template_id ) {
$email_render = Email_Render::init();
$email_render->other_message_content = wpautop($email['message']);
$email_render->recover_heading = str_replace( '[%s]','', $email['subject'] );
$email_render->use_default_template = true;
$data = get_post_meta( $this->template_id, 'viwec_email_structure', true );
$data = json_decode( html_entity_decode( $data ), true );
ob_start();
$email_render->render( $data );
$email['message'] = ob_get_clean();
$email['headers'] = [ "Content-Type: text/html" ];
}
return $email;
}
public function replace_wp_new_user_email( $wp_new_user_notification_email, $user, $blogname ) {
$this->template_id = $this->get_template_id_no_order( 'customer_new_account' );
@ -405,7 +433,50 @@ class Email_Trigger {
return $wp_new_user_notification_email;
}
public function replace_wp_reset_password_title( $title, $user_login, $user_data ) {
$this->template_id = $this->get_template_id_no_order( 'customer_reset_password' );
if ( $this->template_id ) {
$subject = get_post( $this->template_id )->post_title;
if ( $subject ) {
$shortcodes = Utils::default_shortcode_for_replace();
$shortcodes['{user_login}'] = $user_login;
$title = str_replace( array_keys( $shortcodes ), array_values( $shortcodes ), $subject );
}
}
return $title;
}
public function replace_wp_reset_password_email( $message, $key, $user_login, $user_data ) {
if ( $this->template_id ) {
$locale = get_user_locale( $user_data );
$reset_url = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . '&wp_lang=' . $locale;
$register_data = [];
$register_data['password'] = $reset_url;
$user_data->register_data = $register_data;
$email_render = Email_Render::init();
$email_render->set_user( $user_data );
$data = get_post_meta( $this->template_id, 'viwec_email_structure', true );
$data = json_decode( html_entity_decode( $data ), true );
ob_start();
$email_render->render( $data );
$email_body = ob_get_clean();
if ( $email_body ) {
$message = $email_body;
add_filter( 'wp_mail_content_type', [ $this, 'replace_wp_email_type_to_html' ] );
}
}
return $message;
}
public function replace_wp_email_type_to_html() {
return 'text/html';
}
public function remove_style( $style ) {
return $this->clear_css ? '' : $style;
}

View file

@ -213,8 +213,8 @@ class Init {
if ( class_exists( 'VillaTheme_Support' ) ) {
new \VillaTheme_Support(
array(
'support' => 'https://wordpress.org/support/plugin/',
'docs' => 'http://docs.villatheme.com/?item=woocommerce-email-template-customizer',
'support' => 'https://wordpress.org/support/plugin/email-template-customizer-for-woo/',
'docs' => 'https://docs.villatheme.com/?item=woo-email-template-customizer',
'review' => 'https://wordpress.org/support/plugin/email-template-customizer-for-woo/reviews/?rate=5#rate-response',
'pro_url' => 'https://1.envato.market/BZZv1',
'css' => VIWEC_CSS,

View file

@ -7,12 +7,12 @@ if ( ! class_exists( 'VillaTheme_Support' ) ) {
/**
* Class VillaTheme_Support
* 1.1.14
* 1.1.15
*/
class VillaTheme_Support {
protected $plugin_base_name;
protected $ads_data;
protected $version = '1.1.14';
protected $version = '1.1.15';
protected $data = [];
public function __construct( $data ) {
@ -935,78 +935,26 @@ if ( ! class_exists( 'VillaTheme_Require_Environment' ) ) {
$this->notices[] = sprintf( "WordPress version at least %s.", esc_html( $args['wp_version'] ) );
}
if ( ! empty( $args['require_plugins'] ) ) {
$default_headers = array(
'Version' => 'Version',
);
$active_plugins = [];
$tmp = get_option( 'active_plugins' ,[]);
if (is_multisite()){
$tmp += array_keys(get_site_option( 'active_sitewide_plugins', [] ));
}
if (!empty($tmp)){
foreach ($tmp as $v){
$info = explode('/',$v);
if (empty($info[1])){
$info= explode(DIRECTORY_SEPARATOR, $v);
}
if (empty($info[1])){
continue;
}
$active_plugins[$info[0]] = $v;
}
}
$plugins_dir = WP_PLUGIN_DIR;
foreach ( $args['require_plugins'] as $plugin ) {
if (!is_array($plugin) || empty($plugin)){
if (!is_array($plugin) || empty($plugin) || empty($plugin['defined_version'])){
continue;
}
$plugin_name = $plugin['name'] ?? '';
$plugin_slug = $plugin['slug'] ?? '';
$plugin_file = $plugin['file'] ?? '';
$plugin_version = $plugin['version']?? $plugin['required_version'] ?? '';
if (!$plugin_version && $plugin_slug ==='woocommerce'){
$plugin_version = $args['wc_version']??'';
}
$plugin['version'] = $plugin_version;
$is_installed = true;
if (empty($active_plugins[$plugin_slug])){
if (!is_dir($plugins_dir. DIRECTORY_SEPARATOR . $plugin_slug )) {
$is_installed = false;
$this->notices[] = sprintf( "%s to be installed. <br><a href='%s' target='_blank' class='button button-primary' style='vertical-align: middle; margin-top: 5px;'>Install %s</a>",
esc_html( $plugin_name ),
esc_url( current_user_can( 'install_plugins' ) ? wp_nonce_url( network_admin_url( "update.php?action=install-plugin&plugin={$plugin_slug}" ), "install-plugin_{$plugin_slug}" ) : '#' ),
esc_html( $plugin_name ) );
}else{
$msg = sprintf('%s is installed and activated.', esc_html( $plugin_name ));
if (current_user_can( 'activate_plugin', $plugin_file) ) {
$activate_url = add_query_arg(
[
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin_file ),
'action' => 'activate',
'plugin' => $plugin_file,
],
self_admin_url( 'plugins.php' )
);
$msg .= sprintf( " <br> <a href='%s' target='_blank' class='button button-primary' style='vertical-align: middle; margin-top: 5px;'>Active %s</a>",
esc_url( $activate_url ),
esc_html( $plugin_name ) );
}
if (!defined($plugin['defined_version'])){
$msg = sprintf('%s is <a href="%s" target="_blank">installed and activated.</a>', esc_html( $plugin_name ), network_admin_url( "plugin-install.php?s={$plugin_slug}&tab=search&type=term" ) );
$this->notices[] = $msg;
}
}else{
$plugin_file = $active_plugins[$plugin_slug];
}
if ($plugin_version && $is_installed && $plugin_file){
$plugin_file = $plugins_dir.DIRECTORY_SEPARATOR.$plugin_file;
$plugin_info = get_file_data($plugin_file, $default_headers, 'plugin' );
if ( !empty( $plugin_info['Version'] ) && ! version_compare( $plugin_info['Version'], $plugin_version, '>=' )) {
}elseif ($plugin_version && ! version_compare( constant($plugin['defined_version']), $plugin_version, '>=' )) {
$this->notices[] = sprintf( "%s version at least %s.", esc_html( $plugin_name ) ,esc_html( $plugin_version ) );
}
}
}
}
}
public function notice() {
$screen = get_current_screen();

View file

@ -17,34 +17,153 @@ if ( ! defined( 'ABSPATH' ) ) {
<!--[if (mso 16)]>
<style type="text/css">
a {
text-decoration: none;
}
span {
vertical-align: middle;
}
</style>
<![endif]-->
<!--[if mso]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if mso | IE]>
<style type="text/css">
table {
font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;
}
</style>
<![endif]-->
<style type="text/css">
#outlook a {
padding: 0;
<?php echo wp_kses_post( apply_filters('viwec_after_render_style','') )?>
@media screen and (max-width: <?php echo esc_attr($responsive);?>px) {
img {
padding-bottom: 10px;
}
.viwec-responsive{
display: inline-block !important;
}
td.viwec-responsive.viwec-product-responsive *,
.viwec-responsive, .viwec-responsive table, .viwec-button-responsive {
width: 100% !important;
max-width: 100% !important;
min-width: 100% !important;
}
a {
text-decoration: none;
word-break: break-word;
table.viwec-no-full-width-on-mobile {
min-width: 0 !important;
width: auto !important;
}
td.viwec-responsive tbody,
td.viwec-responsive tbody tr,
td.viwec-responsive tbody tr td {
display: inline-block !important;
width: 100% !important;
}
td.viwec-responsive table.viwec-no-full-width-on-mobile td,
td.viwec-responsive table.viwec-no-full-width-on-mobile * td{
width: auto !important;
}
body {
td.viwec-responsive table.viwec-no-full-width-on-mobile,
td.viwec-responsive table.html_wc_hook .html_wc_hook_default table,
td.viwec-responsive table.html_wc_hook .html_wc_hook_default * table {
display: table !important;
}
td.viwec-responsive table.viwec-no-full-width-on-mobile tbody,
td.viwec-responsive table.viwec-no-full-width-on-mobile * tbody,
td.viwec-responsive table.html_wc_hook .html_wc_hook_default tbody,
td.viwec-responsive table.html_wc_hook .html_wc_hook_default * tbody {
display: table-row-group !important;
}
td.viwec-responsive table.viwec-no-full-width-on-mobile tr,
td.viwec-responsive table.viwec-no-full-width-on-mobile * tr,
td.viwec-responsive table.html_wc_hook .html_wc_hook_default tr,
td.viwec-responsive table.html_wc_hook .html_wc_hook_default * tr {
display: table-row !important;
}
td.viwec-responsive table.viwec-no-full-width-on-mobile td,
td.viwec-responsive table.viwec-no-full-width-on-mobile * td,
td.viwec-responsive table.html_wc_hook .html_wc_hook_default td,
td.viwec-responsive table.html_wc_hook .html_wc_hook_default * td {
display: table-cell !important;
}
.viwec-responsive-padding {
padding: 0 !important;
}
.viwec-mobile-hidden {
display: none !important;
}
.viwec-responsive-center, .viwec-responsive-center p, .viwec-center-on-mobile p {
text-align: center !important;
}
.viwec-mobile-50,
table.viwec-responsive tbody tr td.viwec-mobile-50 {
width: 50% !important;
min-width: 50% !important;
max-width: 50% !important;
}
.viwec-mobile-50 .woocommerce-Price-amount {
margin-right: 1px;
}
#viwec-responsive-min-width {
min-width: 100% !important;
}
}
#viwec-responsive-wrap {
box-sizing:border-box;
margin: 0;
padding: 0;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
#viwec-responsive-wrap *{
color:inherit;
box-sizing: border-box;
}
#viwec-responsive-min-width {
min-width: <?php echo esc_attr($width);?>px;
}
#viwec-responsive-wrap #body_content {
width: 100% !important;
}
#viwec-responsive-wrap #outlook a {
padding: 0;
}
img {
#viwec-responsive-wrap a {
text-decoration: none;
word-break: break-word;
}
#viwec-responsive-wrap td {
overflow: hidden;
}
td.viwec-row {
background-repeat: no-repeat;
background-size: cover;
background-position: top;
}
td.viwec-responsive *{
max-width: 100% ;
}
div.viwec-responsive {
display: inline-block;
}
#viwec-responsive-wrap img {
border: 0;
height: auto;
line-height: 100%;
@ -55,19 +174,14 @@ if ( ! defined( 'ABSPATH' ) ) {
background-color: transparent;
max-width: 100%;
}
p {
#viwec-responsive-wrap p {
display: block;
margin: 0;
line-height: inherit;
/*font-size: inherit;*/
}
div.viwec-responsive {
display: inline-block;
}
small {
#viwec-responsive-wrap small {
display: block;
font-size: 13px;
}
@ -79,128 +193,22 @@ if ( ! defined( 'ABSPATH' ) ) {
#viwec-transferred-content td {
vertical-align: top;
}
td.viwec-row {
background-repeat: no-repeat;
background-size: cover;
background-position: top;
}
</style>
<!--[if mso]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if mso | IE]>
<style type="text/css">
.viwec-responsive {
width: 100% !important;
}
small {
display: block;
font-size: 13px;
}
table {
font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;
}
</style>
<![endif]-->
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);
@import url(https://fonts.googleapis.com/css?family=Oswald:300,400,500,700);
</style>
<style type="text/css">
@media only screen and (min-width: <?php echo esc_attr($responsive);?>px) {
a {
text-decoration: none;
word-break: break-word;
}
td {
overflow: hidden;
}
table {
font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;
}
div.viwec-responsive {
display: inline-block;
}
.viwec-responsive-min-width {
min-width: <?php echo esc_attr($width);?>px;
}
}
@media only screen and (max-width: <?php echo esc_attr($responsive);?>px) {
a {
text-decoration: none;
}
td {
overflow: hidden;
}
table {
font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;
}
img {
padding-bottom: 10px;
}
.viwec-responsive, .viwec-responsive table, .viwec-button-responsive {
width: 100% !important;
min-width: 100%;
}
#viwec-transferred-content img {
width: 100% !important;
}
.viwec-no-full-width-on-mobile {
min-width: auto !important;
}
.viwec-responsive-padding {
padding: 0 !important;
}
.viwec-mobile-hidden {
display: none !important;
}
.viwec-responsive-center, .viwec-responsive-center p {
text-align: center !important;
}
.viwec-mobile-50 {
width: 50% !important;
}
.viwec-center-on-mobile p {
text-align: center !important;
}
}
<?php echo wp_kses_post( apply_filters('viwec_after_render_style','') )?>
</style>
</head>
<body vlink="#FFFFFF" <?php echo esc_attr($direction == 'rtl' ? 'rightmargin' : 'leftmargin'); ?>="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
<div id="wrapper" style="box-sizing:border-box;padding:0;margin:0;<?php echo esc_attr( $bg_style ); ?>">
<div id="viwec-responsive-wrap" style="<?php echo esc_attr( $bg_style ); ?>">
<table border="0" cellpadding="0" cellspacing="0" height="100%" align="center" width="100%" style="margin: 0;">
<tbody>
<tr>

View file

@ -8,6 +8,16 @@ $currency_label = esc_html__( 'Subtotal', 'viwec-email-template-customizer' ) .
?>
<div>
<?php
if ( function_exists( 'icl_get_languages' ) || class_exists( 'TRP_Translate_Press' ) ) {
?>
<div class="viwec-setting-row" data-attr="country">
<label><?php esc_html_e( 'Apply to languages', 'viwec-email-template-customizer' ) ?></label>
<?php viwec_get_pro_version() ?>
</div>
<?php
}
?>
<div class="viwec-setting-row" data-attr="country">
<label><?php esc_html_e( 'Apply to billing countries', 'viwec-email-template-customizer' ) ?></label>
<?php viwec_get_pro_version() ?>

View file

@ -19,7 +19,7 @@ $th_style_left = "border:1px solid #dddddd; text-align:{$left_align}; padding:
$th_style_center = 'border:1px solid #dddddd; text-align:center; padding: 10px;';
$th_style_right = 'border:1px solid #dddddd; text-align:right; padding: 10px;';
$html = "<table width='100%' border='0' cellpadding='0' cellspacing='0' align='center' style='{$item_style}; border-collapse:collapse;line-height: 1'>";
$html = "<table class='viwec-no-full-width-on-mobile' width='100%' border='0' cellpadding='0' cellspacing='0' align='center' style='{$item_style}; border-collapse:collapse;line-height: 1'>";
$html .= "<tr><th style='{$th_style_left}'>{$trans_product}</th><th style='{$th_style_center}'>{$trans_quantity}</th><th style='{$th_style_right}{$col_width}'>{$trans_price}</th></tr>";
ob_start();

View file

@ -13,6 +13,7 @@ $remove_product_link = ! empty( $props['attrs']['remove_product_link'] ) && $pro
$trans_quantity = $props['content']['quantity'] ?? 'x';
$font_size = '15px';
$item_id_start = 0;
$list_items_key = array_keys( $items );
$end_id = end( $list_items_key );
@ -27,20 +28,136 @@ foreach ( $items as $item_id => $item ) {
}
$product = $item->get_product();
$sku = $purchase_note = '';
$sku = $purchase_note = $img_url= '';
$p_url = '#';
if ( ! is_object( $product ) ) {
continue;
if ( is_object( $product ) ) {
$sku = $product->viwec_product_sku ?? (method_exists($product,'get_sku')? $product->get_sku(): '');
$purchase_note = $product->viwec_purchase_note ?? (method_exists($product,'get_purchase_note')? $product->get_purchase_note():'');
if (!$remove_product_link) {
$p_url = $product->viwec_product_permalink ?? ( method_exists( $product, 'get_purchase_note' ) ? $product->get_permalink() : '' );
}
if (isset($product->viwec_product_img_url)){
$img_url = $product->viwec_product_img_url;
}else{
$img_url = $product && method_exists($product,'get_image_id') ? wp_get_attachment_image_url( $product->get_image_id(), 'woocommerce_thumbnail' ):wc_placeholder_img_src();
}
}
$img_url = apply_filters( 'viwec_order_item_thumbnail_url',$img_url,$product, $item);
if (!$item_id_start){
$item_id_start = $item_id;
}
$tmp_item_style = $item_style.'border-collapse:collapse;font-size: 0;';
$tmp_item_distance = '';
if ($item_id_start != $item_id){
$tmp_item_distance = 'width: 100%;'.$items_distance;
}
if ($tmp_item_distance){
?>
<table width="100%">
<tr>
<td style='<?php echo esc_attr( $tmp_item_distance ); ?>'></td>
</tr>
</table>
<?php
}
?>
<table width='100%' border='0' cellpadding='0' cellspacing='0' align='center' valign="middle" style='<?php echo esc_attr( $tmp_item_style ) ?>'>
<tr>
<td valign='middle' class="viwec-responsive viwec-product-responsive" style="display:inline-block;overflow: hidden;width:<?php echo esc_attr($img_width)?>px;">
<table border="0" cellpadding="0" cellspacing="0" valign="middle" style="border-collapse: collapse;width: 100%;">
<tr>
<td valign="middle">
<?php
if ( function_exists( 'fpd_get_option' ) && fpd_get_option( 'fpd_order_product_thumbnail' ) ) {
ob_start();
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, false );
$img = ob_get_clean();
$image = str_replace( [ 'border: 1px solid #ccc; float: left; margin-right: 5px; margin-bottom: 5px; max-width: 30%;' ], '', trim( $img ) );
}else{
$image = sprintf( "<img width='%s' src='%s' style='width: 100%%;max-width: 100%%;'>",esc_attr( $img_width ), esc_url( $img_url ) );
}
?>
<a href="<?php echo esc_url( $p_url ) ?>" style="width:<?php echo esc_attr($img_width)?>px;">
<?php echo apply_filters( 'viwec_order_item_thumbnail', $image, $item ); ?>
</a>
</td>
</tr>
</table>
</td>
<td valign='middle' class="viwec-responsive" style="display:inline-block;overflow: hidden;width:<?php echo esc_attr($name_width)?>px;">
<table border="0" cellpadding="0" cellspacing="0" valign="middle"
style="width: 100%;border-collapse: collapse;line-height: 150%;font-size: <?php echo esc_attr( $font_size ) ?>">
<tr>
<td class="viwec-mobile-hidden" valign="middle" style="font-size:0;padding: 0;width: 15px;"></td>
<td valign="middle" class="viwec-responsive-center">
<a href="<?php echo esc_url( $p_url ) ?>" class="viwec-responsive-center">
<span style="<?php echo esc_attr( $name_style ) ?>">
<?php
echo ( apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ) );// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ( $show_sku && $sku ) {
echo '<small>' . wp_kses_post( ' (#' . $sku . ')' ) . '</small>';
}
?>
</span>
</a>
<p style="<?php echo esc_attr( $quantity_size ) ?>">
<?php
echo esc_html( $trans_quantity ) . ' ';
$qty = $item->get_quantity();
$refunded_qty = $order->get_qty_refunded_for_item( $item_id );
if ( $refunded_qty ) {
$qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * - 1 ) ) . '</ins>';
} else {
$qty_display = esc_html( $qty );
}
echo ( apply_filters( 'woocommerce_email_order_item_quantity', $qty_display, $item ) );// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<br>';
?>
</p>
<div class="woocommerce-order-item-meta">
<?php
if ( ! ( function_exists( 'fpd_get_option' ) && fpd_get_option( 'fpd_order_product_thumbnail' ) ) ) {
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, false );
}
wc_display_item_meta(
$item,
[
'before' => '<div class="wc-item-meta"><div>',
'after' => '</div></div>',
'separator' => '</div><div>',
'echo' => true,
'autop' => false,
'label_before' => '<span class="wc-item-meta-label">',
'label_after' => ':</span> ',
]
);
$sku = $product->get_sku();
$purchase_note = $product->get_purchase_note();
$p_url = $remove_product_link ? '#' : $product->get_permalink();
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, false );
?>
</div>
<p style="<?php echo esc_attr( $price_size ) ?>">
<?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?>
</p>
<?php
do_action( 'viwec_order_item_parts', $item_id, $item, $order, false );
if ( $show_purchase_note && $purchase_note ) {
echo wp_kses_post( wpautop( do_shortcode( $purchase_note ) ) );
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
continue;
$img_url = wp_get_attachment_image_url( $product->get_image_id(), 'woocommerce_thumbnail' );
$image = sprintf( "<img width='%s' src='%s'>", esc_attr( $img_width ), esc_url( $img_url ) );
?>
<table width='100%' border='0' cellpadding='0' cellspacing='0' align='center'
style='<?php echo esc_attr( $item_style ) ?> border-collapse:collapse;font-size: 0;'>
<tr>
@ -145,7 +262,6 @@ foreach ( $items as $item_id => $item ) {
<div style='width: 100%; <?php echo esc_attr( $items_distance ); ?>'></div>
<?php
}
}

View file

@ -4,7 +4,7 @@ defined( 'ABSPATH' ) || exit;
$text_align = $direction == 'rtl' ? 'right' : 'left';
$margin_side = $direction == 'rtl' ? 'left' : 'right';
$item_style = ! empty( $props['childStyle']['.viwec-item-row'] ) ? $render->parse_styles( $props['childStyle']['.viwec-item-row'] ) : '';
$name_size = ! empty( $props['childStyle']['.viwec-product-name'] ) ? $render->parse_styles( $props['childStyle']['.viwec-product-name'] ) : '';
$name_style = ! empty( $props['childStyle']['.viwec-product-name'] ) ? $render->parse_styles( $props['childStyle']['.viwec-product-name'] ) : '';
$quantity_size = ! empty( $props['childStyle']['.viwec-product-quantity'] ) ? $render->parse_styles( $props['childStyle']['.viwec-product-quantity'] ) : '';
$price_size = ! empty( $props['childStyle']['.viwec-product-price'] ) ? $render->parse_styles( $props['childStyle']['.viwec-product-price'] ) : '';
$items_distance = ! empty( $props['childStyle']['.viwec-product-distance'] ) ? $render->parse_styles( $props['childStyle']['.viwec-product-distance'] ) : '';
@ -15,6 +15,7 @@ $trans_quantity = $props['content']['quantity'] ?? 'x';
$font_size = '15px';
$list_items_key = array_keys( $items );
$end_id = end( $list_items_key );
$item_id_start = 0;
$parent_width = ! empty( $props['style']['width'] ) ? str_replace( 'px', '', $props['style']['width'] ) : 600;
$img_width = ! empty( $props['childStyle']['.viwec-product-img']['width'] ) ? str_replace( 'px', '', $props['childStyle']['.viwec-product-img']['width'] ) : 150;
@ -30,13 +31,135 @@ foreach ( $items as $item_id => $item ) {
$product = $item->get_product();
$sku = $purchase_note = '';
if ( ! is_object( $product ) ) {
continue;
$sku = $product->viwec_product_sku ?? (method_exists($product,'get_sku')? $product->get_sku(): '');
$purchase_note = $product->viwec_purchase_note ?? (method_exists($product,'get_purchase_note')? $product->get_purchase_note():'');
if (!$remove_product_link) {
$p_url = $product->viwec_product_permalink ?? ( method_exists( $product, 'get_purchase_note' ) ? $product->get_permalink() : '' );
}
$sku = $product->get_sku();
$purchase_note = $product->get_purchase_note();
$p_url = $remove_product_link ? '#' : $product->get_permalink();
if (!$item_id_start){
$item_id_start = $item_id;
}
$tmp_item_style = $item_style.'border-collapse:collapse;font-size: 0;';
$tmp_item_distance = '';
if ($item_id_start != $item_id){
$tmp_item_distance = 'width: 100%;'.$items_distance;
}
if (isset($product->viwec_product_img_url)){
$img_url = $product->viwec_product_img_url;
}else{
$img_url = $product && method_exists($product,'get_image_id') ? wp_get_attachment_image_url( $product->get_image_id(), 'woocommerce_thumbnail' ):wc_placeholder_img_src();
}
$img_url = apply_filters( 'viwec_order_item_thumbnail_url',$img_url,$product, $item);
if ($tmp_item_distance){
?>
<table width="100%">
<tr>
<td style='<?php echo esc_attr( $tmp_item_distance ); ?>'></td>
</tr>
</table>
<?php
}
?>
<table width='100%' border='0' cellpadding='0' cellspacing='0' align='center' valign="middle" style='<?php echo esc_attr( $tmp_item_style ) ?>'>
<tr>
<td valign='middle' class="viwec-responsive viwec-product-responsive" style="overflow: hidden;width:<?php echo esc_attr(100*$img_width/$parent_width)?>%;">
<table border="0" cellpadding="0" cellspacing="0" valign="middle" style="border-collapse: collapse;width: 100%;">
<tr>
<td valign="middle">
<?php
if ( function_exists( 'fpd_get_option' ) && fpd_get_option( 'fpd_order_product_thumbnail' ) ) {
ob_start();
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, false );
$img = ob_get_clean();
$image = str_replace( [ 'border: 1px solid #ccc; float: left; margin-right: 5px; margin-bottom: 5px; max-width: 30%;' ], '', trim( $img ) );
}else{
$image = sprintf( "<img width='%s' src='%s' style='width: 100%%;max-width: 100%%;'>",esc_attr( $img_width ), esc_url( $img_url ) );
}
?>
<a href="<?php echo esc_url( $p_url ) ?>" style="width:<?php echo esc_attr($img_width)?>px;">
<?php echo apply_filters( 'viwec_order_item_thumbnail', $image, $item ); ?>
</a>
</td>
</tr>
</table>
</td>
<td valign='middle' class="viwec-responsive" style="overflow: hidden;width:<?php echo esc_attr($name_width)?>px;">
<table border="0" cellpadding="0" cellspacing="0" valign="middle"
style="width: 100%;border-collapse: collapse;line-height: 150%;font-size: <?php echo esc_attr( $font_size ) ?>">
<tr>
<td class="viwec-mobile-hidden" valign="middle" style="font-size:0;padding: 0;width: 15px;"></td>
<td valign="middle" class="viwec-responsive-center">
<a href="<?php echo esc_url( $p_url ) ?>" class="viwec-responsive-center">
<span style="<?php echo esc_attr( $name_style ) ?>">
<?php
echo wp_kses_post( apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ) );
if ( $show_sku && $sku ) {
echo '<small>' . wp_kses_post( ' (#' . $sku . ')' ) . '</small>';
}
?>
</span>
</a>
<p style="<?php echo esc_attr( $quantity_size ) ?>">
<?php
echo esc_html( $trans_quantity ) . ' ';
$qty = $item->get_quantity();
$refunded_qty = $order->get_qty_refunded_for_item( $item_id );
if ( $refunded_qty ) {
$qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * - 1 ) ) . '</ins>';
} else {
$qty_display = esc_html( $qty );
}
echo wp_kses_post( apply_filters( 'woocommerce_email_order_item_quantity', $qty_display, $item ) );
echo '<br>';
?>
</p>
<div class="woocommerce-order-item-meta">
<?php
if ( ! ( function_exists( 'fpd_get_option' ) && fpd_get_option( 'fpd_order_product_thumbnail' ) ) ) {
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, false );
}
wc_display_item_meta(
$item,
array(
'before' => '<div class=""><div>',
'after' => '</div></div>',
'separator' => '</div><div>',
'label_before' => '<strong class="wc-item-meta-label" style="float: ' . esc_attr( $text_align ) . '; margin-' . esc_attr( $margin_side ) . ': .25em; clear: both">',
)
);
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, false );
?>
</div>
<?php
do_action( 'viwec_order_item_parts', $item_id, $item, $order, false );
if ( $show_purchase_note && $purchase_note ) {
echo wp_kses_post( wpautop( do_shortcode( $purchase_note ) ) );
}
?>
</td>
</tr>
</table>
</td>
<td valign='middle' class="viwec-responsive" style='overflow: hidden;width: <?php echo esc_attr( $price_width ) ?>px;'>
<table border="0" cellpadding="0" cellspacing="0" valign="middle"
style='width: 100%;text-align:right;line-height: 150%;font-size: <?php echo esc_attr( $font_size ) ?>'>
<tr>
<td class="viwec-mobile-hidden" valign="middle" style="font-size:0;padding: 0;width: 15px;"></td>
<td class="viwec-responsive-center" valign='middle' style="vertical-align: middle; text-align: right;">
<p style="text-align:<?php echo esc_attr( $margin_side ) ?>;white-space: nowrap;min-width: fit-content;<?php echo esc_attr( $price_size ) ?>">
<?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) );// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
continue;
$img_url = wp_get_attachment_image_url( $product->get_image_id(), 'woocommerce_thumbnail' );
$image = sprintf( "<img width='%s' src='%s'>", esc_attr( $img_width ), esc_url( $img_url ) );
?>
@ -77,7 +200,7 @@ foreach ( $items as $item_id => $item ) {
<td class="viwec-mobile-hidden" valign="middle" style="font-size:0;padding: 0;width: 15px;"></td>
<td valign="middle" class="viwec-responsive-center">
<a href="<?php echo esc_url( $p_url ) ?>" class="viwec-responsive-center">
<span style="margin:0;padding:0;<?php echo esc_attr( $name_size ) ?>" class="viwec-responsive-center">
<span style="margin:0;padding:0;<?php echo esc_attr( $name_style ) ?>" class="viwec-responsive-center">
<?php
echo wp_kses_post( apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ) );
if ( $show_sku && $sku ) {

View file

@ -329,7 +329,7 @@ class Utils {
$r = [
'default' => [ 'min_order', 'max_order', 'category', 'country' ],
'customer_new_account' => [ 'min_order', 'max_order', 'category' ],
'customer_reset_password' => [ 'min_order', 'max_order', 'category' ]
'customer_reset_password' => [ 'min_order', 'max_order', 'category', 'country' ]
];
$register_email_type = self::register_3rd_email_type();

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-element', 'wp-hooks'), 'version' => '6834c450faf198afa279');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-element', 'wp-hooks'), 'version' => '18a7069ef0ddadd849a6');

View file

@ -1 +1 @@
(()=>{"use strict";var e,r={898:()=>{window.React,window.wp.hooks,window.wp.element,window.ReactDOM,window.wp.apiFetch,window.lodash}},o={};function i(e){var n=o[e];if(void 0!==n)return n.exports;var t=o[e]={exports:{}};return r[e](t,t.exports,i),t.exports}i.m=r,e=[],i.O=(r,o,n,t)=>{if(!o){var a=1/0;for(w=0;w<e.length;w++){for(var[o,n,t]=e[w],l=!0,p=0;p<o.length;p++)(!1&t||a>=t)&&Object.keys(i.O).every((e=>i.O[e](o[p])))?o.splice(p--,1):(l=!1,t<a&&(a=t));if(l){e.splice(w--,1);var s=n();void 0!==s&&(r=s)}}return r}t=t||0;for(var w=e.length;w>0&&e[w-1][2]>t;w--)e[w]=e[w-1];e[w]=[o,n,t]},i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={765:0,786:0};i.O.j=r=>0===e[r];var r=(r,o)=>{var n,t,[a,l,p]=o,s=0;if(a.some((r=>0!==e[r]))){for(n in l)i.o(l,n)&&(i.m[n]=l[n]);if(p)var w=p(i)}for(r&&r(o);s<a.length;s++)t=a[s],i.o(e,t)&&e[t]&&e[t][0](),e[t]=0;return i.O(w)},o=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];o.forEach(r.bind(null,0)),o.push=r.bind(null,o.push.bind(o))})();var n=i.O(void 0,[786],(()=>i(898)));n=i.O(n)})();
(()=>{"use strict";var e,r={17:()=>{window.React,window.wp.hooks,window.wp.element,window.ReactDOM,window.wp.apiFetch,window.lodash}},o={};function i(e){var n=o[e];if(void 0!==n)return n.exports;var t=o[e]={exports:{}};return r[e](t,t.exports,i),t.exports}i.m=r,e=[],i.O=(r,o,n,t)=>{if(!o){var a=1/0;for(w=0;w<e.length;w++){for(var[o,n,t]=e[w],l=!0,p=0;p<o.length;p++)(!1&t||a>=t)&&Object.keys(i.O).every((e=>i.O[e](o[p])))?o.splice(p--,1):(l=!1,t<a&&(a=t));if(l){e.splice(w--,1);var s=n();void 0!==s&&(r=s)}}return r}t=t||0;for(var w=e.length;w>0&&e[w-1][2]>t;w--)e[w]=e[w-1];e[w]=[o,n,t]},i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={858:0,966:0};i.O.j=r=>0===e[r];var r=(r,o)=>{var n,t,[a,l,p]=o,s=0;if(a.some((r=>0!==e[r]))){for(n in l)i.o(l,n)&&(i.m[n]=l[n]);if(p)var w=p(i)}for(r&&r(o);s<a.length;s++)t=a[s],i.o(e,t)&&e[t]&&e[t][0](),e[t]=0;return i.O(w)},o=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];o.forEach(r.bind(null,0)),o.push=r.bind(null,o.push.bind(o))})();var n=i.O(void 0,[966],(()=>i(17)));n=i.O(n)})();

View file

@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wc-blocks-checkout', 'wp-api-fetch', 'wp-element', 'wp-hooks'), 'version' => '52b0d1b2dc6a52a4240e');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wc-blocks-checkout', 'wp-api-fetch', 'wp-element', 'wp-hooks'), 'version' => 'fa89fe2491b3f9a2a135');

View file

@ -1 +1 @@
(()=>{"use strict";var e,t={898:(e,t,o)=>{o.d(t,{g:()=>s});const i=window.React,n=window.wp.hooks,l=window.wp.element,r=window.ReactDOM,c=(window.wp.apiFetch,window.lodash),a=({pageType:e})=>{const[t,o]=(0,l.useState)([]),r=(0,i.useCallback)((0,c.debounce)((()=>{wp.apiFetch({path:"flexible-shipping/v1/free-shipping-notice",method:"GET"}).then((e=>{o(e)})).catch((e=>{console.log(e)}))}),2e3),[]);return(0,l.useEffect)((()=>{document.body.addEventListener("wc-blocks_added_to_cart",(e=>{r()})),(0,n.addAction)("flexible-shipping-cart-updated","flexible-shipping",r),r()}),[]),(0,i.createElement)(i.Fragment,null,t.map(((t,o)=>null==e||t.blocks.includes(e)?(0,i.createElement)("div",{key:o,className:"woocommerce-info",dangerouslySetInnerHTML:{__html:t.content}}):null)))},s=({checkoutExtensionData:e,cart:t,extensions:o})=>{const{setExtensionData:c}=e||{};return(0,l.useEffect)((()=>{0===document.querySelectorAll(".flexible-shipping-free-shipping-root").length&&void 0!==o["flexible-shipping-free-shipping-notice-block-integration"]&&(e=>{let t=document.getElementsByClassName("wp-block-woocommerce-cart");if(0===t.length&&(t=document.getElementsByClassName("wp-block-woocommerce-checkout")),t.length>0){const o=document.createElement("div");t[0].parentNode.insertBefore(o,t[0]),(0,r.createRoot)(o).render((0,i.createElement)(a,{pageType:e}))}})(o["flexible-shipping-free-shipping-notice-block-integration"].page_type)}),[]),(0,l.useEffect)((()=>{c&&c("flexible-shipping-free-shipping-notice-block-integration","fakeField","")}),[]),(0,l.useEffect)((()=>{(0,n.doAction)("flexible-shipping-cart-updated","flexible-shipping",{})}),[t]),(0,i.createElement)(i.Fragment,null)}},701:(e,t,o)=>{const i=window.wc.blocksCheckout;var n=o(898);const l=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"flexible-shipping/free-shipping-notice-block-integration","version":"1.0.0","title":"Free Shipping Notice Block Integration","category":"woocommerce","description":"Adds a notice to the checkout and cart when free shipping is available.","supports":{"html":false,"align":false,"multiple":false,"reusable":false},"parent":["woocommerce/checkout-shipping-methods-block","woocommerce/cart-totals-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}}},"textdomain":"flexible-shipping","editorScript":"file:./index.js","style":"file:./style-index.css","viewScript":"file:./frontend.js"}');(0,i.registerCheckoutBlock)({metadata:l,component:n.g})}},o={};function i(e){var n=o[e];if(void 0!==n)return n.exports;var l=o[e]={exports:{}};return t[e](l,l.exports,i),l.exports}i.m=t,e=[],i.O=(t,o,n,l)=>{if(!o){var r=1/0;for(p=0;p<e.length;p++){for(var[o,n,l]=e[p],c=!0,a=0;a<o.length;a++)(!1&l||r>=l)&&Object.keys(i.O).every((e=>i.O[e](o[a])))?o.splice(a--,1):(c=!1,l<r&&(r=l));if(c){e.splice(p--,1);var s=n();void 0!==s&&(t=s)}}return t}l=l||0;for(var p=e.length;p>0&&e[p-1][2]>l;p--)e[p]=e[p-1];e[p]=[o,n,l]},i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={979:0,765:0,786:0};i.O.j=t=>0===e[t];var t=(t,o)=>{var n,l,[r,c,a]=o,s=0;if(r.some((t=>0!==e[t]))){for(n in c)i.o(c,n)&&(i.m[n]=c[n]);if(a)var p=a(i)}for(t&&t(o);s<r.length;s++)l=r[s],i.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return i.O(p)},o=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var n=i.O(void 0,[786],(()=>i(701)));n=i.O(n)})();
(()=>{"use strict";var e,t={17:(e,t,o)=>{o.d(t,{e:()=>s});const i=window.React,n=window.wp.hooks,l=window.wp.element,r=window.ReactDOM,c=(window.wp.apiFetch,window.lodash),a=({pageType:e})=>{const[t,o]=(0,l.useState)([]),r=(0,i.useCallback)((0,c.debounce)((()=>{wp.apiFetch({path:"flexible-shipping/v1/free-shipping-notice",method:"GET"}).then((e=>{o(e)})).catch((e=>{console.log(e)}))}),2e3),[]);return(0,l.useEffect)((()=>{document.body.addEventListener("wc-blocks_added_to_cart",(e=>{r()})),(0,n.addAction)("flexible-shipping-cart-updated","flexible-shipping",r),r()}),[]),(0,i.createElement)(i.Fragment,null,t.map(((t,o)=>null==e||t.blocks.includes(e)?(0,i.createElement)("div",{key:o,className:"woocommerce-info",dangerouslySetInnerHTML:{__html:t.content}}):null)))},s=({checkoutExtensionData:e,cart:t,extensions:o})=>{const{setExtensionData:c}=e||{};return(0,l.useEffect)((()=>{0===document.querySelectorAll(".flexible-shipping-free-shipping-root").length&&void 0!==o["flexible-shipping-free-shipping-notice-block-integration"]&&(e=>{let t=document.getElementsByClassName("wp-block-woocommerce-cart");if(0===t.length&&(t=document.getElementsByClassName("wp-block-woocommerce-checkout")),t.length>0){const o=document.createElement("div");t[0].parentNode.insertBefore(o,t[0]),(0,r.createRoot)(o).render((0,i.createElement)(a,{pageType:e}))}})(o["flexible-shipping-free-shipping-notice-block-integration"].page_type)}),[]),(0,l.useEffect)((()=>{c&&c("flexible-shipping-free-shipping-notice-block-integration","fakeField","")}),[]),(0,l.useEffect)((()=>{(0,n.doAction)("flexible-shipping-cart-updated","flexible-shipping",{})}),[t]),(0,i.createElement)(i.Fragment,null)}},902:(e,t,o)=>{const i=window.wc.blocksCheckout;var n=o(17);const l=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"flexible-shipping/free-shipping-notice-block-integration","version":"1.0.0","title":"Free Shipping Notice Block Integration","category":"woocommerce","description":"Adds a notice to the checkout and cart when free shipping is available.","supports":{"html":false,"align":false,"multiple":false,"reusable":false},"parent":["woocommerce/checkout-shipping-methods-block","woocommerce/cart-totals-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}}},"textdomain":"flexible-shipping","editorScript":"file:./index.js","style":"file:./style-index.css","viewScript":"file:./frontend.js"}');(0,i.registerCheckoutBlock)({metadata:l,component:n.e})}},o={};function i(e){var n=o[e];if(void 0!==n)return n.exports;var l=o[e]={exports:{}};return t[e](l,l.exports,i),l.exports}i.m=t,e=[],i.O=(t,o,n,l)=>{if(!o){var r=1/0;for(p=0;p<e.length;p++){for(var[o,n,l]=e[p],c=!0,a=0;a<o.length;a++)(!1&l||r>=l)&&Object.keys(i.O).every((e=>i.O[e](o[a])))?o.splice(a--,1):(c=!1,l<r&&(r=l));if(c){e.splice(p--,1);var s=n();void 0!==s&&(t=s)}}return t}l=l||0;for(var p=e.length;p>0&&e[p-1][2]>l;p--)e[p]=e[p-1];e[p]=[o,n,l]},i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={675:0,858:0,966:0};i.O.j=t=>0===e[t];var t=(t,o)=>{var n,l,[r,c,a]=o,s=0;if(r.some((t=>0!==e[t]))){for(n in c)i.o(c,n)&&(i.m[n]=c[n]);if(a)var p=a(i)}for(t&&t(o);s<r.length;s++)l=r[s],i.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return i.O(p)},o=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var n=i.O(void 0,[966],(()=>i(902)));n=i.O(n)})();

View file

@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '0b2c36ad5797e2cee4b2');
<?php return array('dependencies' => array(), 'version' => 'cec456cffd5016d71ebf');

View file

@ -1 +1 @@
(()=>{"use strict";var r,e={146:()=>{}},i={};function o(r){var n=i[r];if(void 0!==n)return n.exports;var l=i[r]={exports:{}};return e[r](l,l.exports,o),l.exports}o.m=e,r=[],o.O=(e,i,n,l)=>{if(!i){var t=1/0;for(v=0;v<r.length;v++){for(var[i,n,l]=r[v],a=!0,p=0;p<i.length;p++)(!1&l||t>=l)&&Object.keys(o.O).every((r=>o.O[r](i[p])))?i.splice(p--,1):(a=!1,l<t&&(t=l));if(a){r.splice(v--,1);var s=n();void 0!==s&&(e=s)}}return e}l=l||0;for(var v=r.length;v>0&&r[v-1][2]>l;v--)r[v]=r[v-1];r[v]=[i,n,l]},o.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={522:0,391:0};o.O.j=e=>0===r[e];var e=(e,i)=>{var n,l,[t,a,p]=i,s=0;if(t.some((e=>0!==r[e]))){for(n in a)o.o(a,n)&&(o.m[n]=a[n]);if(p)var v=p(o)}for(e&&e(i);s<t.length;s++)l=t[s],o.o(r,l)&&r[l]&&r[l][0](),r[l]=0;return o.O(v)},i=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];i.forEach(e.bind(null,0)),i.push=e.bind(null,i.push.bind(i))})();var n=o.O(void 0,[391],(()=>o(146)));n=o.O(n)})();
(()=>{"use strict";var r,e={251:()=>{}},i={};function o(r){var n=i[r];if(void 0!==n)return n.exports;var l=i[r]={exports:{}};return e[r](l,l.exports,o),l.exports}o.m=e,r=[],o.O=(e,i,n,l)=>{if(!i){var t=1/0;for(v=0;v<r.length;v++){for(var[i,n,l]=r[v],a=!0,p=0;p<i.length;p++)(!1&l||t>=l)&&Object.keys(o.O).every((r=>o.O[r](i[p])))?i.splice(p--,1):(a=!1,l<t&&(t=l));if(a){r.splice(v--,1);var s=n();void 0!==s&&(e=s)}}return e}l=l||0;for(var v=r.length;v>0&&r[v-1][2]>l;v--)r[v]=r[v-1];r[v]=[i,n,l]},o.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={949:0,681:0};o.O.j=e=>0===r[e];var e=(e,i)=>{var n,l,[t,a,p]=i,s=0;if(t.some((e=>0!==r[e]))){for(n in a)o.o(a,n)&&(o.m[n]=a[n]);if(p)var v=p(o)}for(e&&e(i);s<t.length;s++)l=t[s],o.o(r,l)&&r[l]&&r[l][0](),r[l]=0;return o.O(v)},i=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];i.forEach(e.bind(null,0)),i.push=e.bind(null,i.push.bind(i))})();var n=o.O(void 0,[681],(()=>o(251)));n=o.O(n)})();

View file

@ -1 +1 @@
<?php return array('dependencies' => array('react'), 'version' => 'b29fb81a6f307c5eb142');
<?php return array('dependencies' => array('react'), 'version' => 'e0c87041d4d253e87554');

View file

@ -1 +1 @@
(()=>{"use strict";var r={196:r=>{r.exports=window.React}},e={};function o(t){var n=e[t];if(void 0!==n)return n.exports;var p=e[t]={exports:{}};return r[t](p,p.exports,o),p.exports}o.n=r=>{var e=r&&r.__esModule?()=>r.default:()=>r;return o.d(e,{a:e}),e},o.d=(r,e)=>{for(var t in e)o.o(e,t)&&!o.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:e[t]})},o.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{o(196);const{__}=wp.i18n,{useBlockProps:r}=wp.blockEditor})()})();
(()=>{"use strict";var r={609:r=>{r.exports=window.React}},e={};function o(t){var n=e[t];if(void 0!==n)return n.exports;var p=e[t]={exports:{}};return r[t](p,p.exports,o),p.exports}o.n=r=>{var e=r&&r.__esModule?()=>r.default:()=>r;return o.d(e,{a:e}),e},o.d=(r,e)=>{for(var t in e)o.o(e,t)&&!o.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:e[t]})},o.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),o(609);const{__}=wp.i18n,{useBlockProps:t}=wp.blockEditor})();

View file

@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor'), 'version' => 'e32e838db2d10d56ef1c');
<?php return array('dependencies' => array('react', 'wp-block-editor'), 'version' => '2f79bf0fadb7deef0f5f');

View file

@ -1 +1 @@
(()=>{"use strict";var e,r={646:(e,r,i)=>{i.d(r,{Z:()=>t});var n=i(196);const{__}=wp.i18n,{useBlockProps:o}=wp.blockEditor;function t(){return(0,n.createElement)("div",{...o()},__("Flexible Shipping Free Shipping Notice","flexible-shipping"))}},422:(e,r,i)=>{var n=i(646),o=i(196);const t=window.wp.blockEditor,p=JSON.parse('{"u2":"flexible-shipping/free-shipping-notice"}'),{registerBlockType:l}=wp.blocks;l(p.u2,{edit:n.Z,save:function(){return(0,o.createElement)("div",{...t.useBlockProps.save()},"Flexible Shipping Free Shipping")}})},196:e=>{e.exports=window.React}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var t=i[e]={exports:{}};return r[e](t,t.exports,n),t.exports}n.m=r,e=[],n.O=(r,i,o,t)=>{if(!i){var p=1/0;for(c=0;c<e.length;c++){for(var[i,o,t]=e[c],l=!0,s=0;s<i.length;s++)(!1&t||p>=t)&&Object.keys(n.O).every((e=>n.O[e](i[s])))?i.splice(s--,1):(l=!1,t<p&&(p=t));if(l){e.splice(c--,1);var a=o();void 0!==a&&(r=a)}}return r}t=t||0;for(var c=e.length;c>0&&e[c-1][2]>t;c--)e[c]=e[c-1];e[c]=[i,o,t]},n.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return n.d(r,{a:r}),r},n.d=(e,r)=>{for(var i in r)n.o(r,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={222:0,338:0,786:0};n.O.j=r=>0===e[r];var r=(r,i)=>{var o,t,[p,l,s]=i,a=0;if(p.some((r=>0!==e[r]))){for(o in l)n.o(l,o)&&(n.m[o]=l[o]);if(s)var c=s(n)}for(r&&r(i);a<p.length;a++)t=p[a],n.o(e,t)&&e[t]&&e[t][0](),e[t]=0;return n.O(c)},i=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];i.forEach(r.bind(null,0)),i.push=r.bind(null,i.push.bind(i))})();var o=n.O(void 0,[786],(()=>n(422)));o=n.O(o)})();
(()=>{"use strict";var e,r={274:(e,r,i)=>{i.d(r,{A:()=>t});var n=i(609);const{__}=wp.i18n,{useBlockProps:o}=wp.blockEditor;function t(){return(0,n.createElement)("div",{...o()},__("Flexible Shipping Free Shipping Notice","flexible-shipping"))}},878:(e,r,i)=>{var n=i(274),o=i(609);const t=window.wp.blockEditor,p=JSON.parse('{"UU":"flexible-shipping/free-shipping-notice"}'),{registerBlockType:l}=wp.blocks;l(p.UU,{edit:n.A,save:function(){return(0,o.createElement)("div",{...t.useBlockProps.save()},"Flexible Shipping Free Shipping")}})},609:e=>{e.exports=window.React}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var t=i[e]={exports:{}};return r[e](t,t.exports,n),t.exports}n.m=r,e=[],n.O=(r,i,o,t)=>{if(!i){var p=1/0;for(c=0;c<e.length;c++){for(var[i,o,t]=e[c],l=!0,s=0;s<i.length;s++)(!1&t||p>=t)&&Object.keys(n.O).every((e=>n.O[e](i[s])))?i.splice(s--,1):(l=!1,t<p&&(p=t));if(l){e.splice(c--,1);var a=o();void 0!==a&&(r=a)}}return r}t=t||0;for(var c=e.length;c>0&&e[c-1][2]>t;c--)e[c]=e[c-1];e[c]=[i,o,t]},n.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return n.d(r,{a:r}),r},n.d=(e,r)=>{for(var i in r)n.o(r,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={364:0,924:0,966:0};n.O.j=r=>0===e[r];var r=(r,i)=>{var o,t,[p,l,s]=i,a=0;if(p.some((r=>0!==e[r]))){for(o in l)n.o(l,o)&&(n.m[o]=l[o]);if(s)var c=s(n)}for(r&&r(i);a<p.length;a++)t=p[a],n.o(e,t)&&e[t]&&e[t][0](),e[t]=0;return n.O(c)},i=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];i.forEach(r.bind(null,0)),i.push=r.bind(null,i.push.bind(i))})();var o=n.O(void 0,[966],(()=>n(878)));o=n.O(o)})();

View file

@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-element', 'wp-hooks'), 'version' => '875c8f0d48279cc92b21');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-element', 'wp-hooks'), 'version' => '7b235a8993893557b8ca');

View file

@ -1 +1 @@
(()=>{"use strict";var e,n={424:()=>{const e=window.React,n=window.ReactDOM,t=window.wp.element,o=window.wp.hooks,r=(window.wp.apiFetch,window.lodash),i=({pageType:n})=>{const[i,l]=(0,t.useState)([]),a=(0,e.useCallback)((0,r.debounce)((()=>{wp.apiFetch({path:"flexible-shipping/v1/free-shipping-notice",method:"GET"}).then((e=>{l(e)})).catch((e=>{console.log(e)}))}),2e3),[]);return(0,t.useEffect)((()=>{document.body.addEventListener("wc-blocks_added_to_cart",(e=>{a()})),(0,o.addAction)("flexible-shipping-cart-updated","flexible-shipping",a),a()}),[]),(0,e.createElement)(e.Fragment,null,i.map(((t,o)=>null==n||t.blocks.includes(n)?(0,e.createElement)("div",{key:o,className:"woocommerce-info",dangerouslySetInnerHTML:{__html:t.content}}):null)))},l=Array.from(document.getElementsByClassName("flexible-shipping-free-shipping-root"));l.length>0&&(0,n.createRoot)(l[0]).render((0,e.createElement)(i,null))}},t={};function o(e){var r=t[e];if(void 0!==r)return r.exports;var i=t[e]={exports:{}};return n[e](i,i.exports,o),i.exports}o.m=n,e=[],o.O=(n,t,r,i)=>{if(!t){var l=1/0;for(p=0;p<e.length;p++){for(var[t,r,i]=e[p],a=!0,s=0;s<t.length;s++)(!1&i||l>=i)&&Object.keys(o.O).every((e=>o.O[e](t[s])))?t.splice(s--,1):(a=!1,i<l&&(l=i));if(a){e.splice(p--,1);var c=r();void 0!==c&&(n=c)}}return n}i=i||0;for(var p=e.length;p>0&&e[p-1][2]>i;p--)e[p]=e[p-1];e[p]=[t,r,i]},o.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),(()=>{var e={299:0,786:0};o.O.j=n=>0===e[n];var n=(n,t)=>{var r,i,[l,a,s]=t,c=0;if(l.some((n=>0!==e[n]))){for(r in a)o.o(a,r)&&(o.m[r]=a[r]);if(s)var p=s(o)}for(n&&n(t);c<l.length;c++)i=l[c],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return o.O(p)},t=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];t.forEach(n.bind(null,0)),t.push=n.bind(null,t.push.bind(t))})();var r=o.O(void 0,[786],(()=>o(424)));r=o.O(r)})();
(()=>{"use strict";var e,n={638:()=>{const e=window.React,n=window.ReactDOM,t=window.wp.element,o=window.wp.hooks,r=(window.wp.apiFetch,window.lodash),i=({pageType:n})=>{const[i,l]=(0,t.useState)([]),a=(0,e.useCallback)((0,r.debounce)((()=>{wp.apiFetch({path:"flexible-shipping/v1/free-shipping-notice",method:"GET"}).then((e=>{l(e)})).catch((e=>{console.log(e)}))}),2e3),[]);return(0,t.useEffect)((()=>{document.body.addEventListener("wc-blocks_added_to_cart",(e=>{a()})),(0,o.addAction)("flexible-shipping-cart-updated","flexible-shipping",a),a()}),[]),(0,e.createElement)(e.Fragment,null,i.map(((t,o)=>null==n||t.blocks.includes(n)?(0,e.createElement)("div",{key:o,className:"woocommerce-info",dangerouslySetInnerHTML:{__html:t.content}}):null)))},l=Array.from(document.getElementsByClassName("flexible-shipping-free-shipping-root"));l.length>0&&(0,n.createRoot)(l[0]).render((0,e.createElement)(i,null))}},t={};function o(e){var r=t[e];if(void 0!==r)return r.exports;var i=t[e]={exports:{}};return n[e](i,i.exports,o),i.exports}o.m=n,e=[],o.O=(n,t,r,i)=>{if(!t){var l=1/0;for(p=0;p<e.length;p++){for(var[t,r,i]=e[p],a=!0,s=0;s<t.length;s++)(!1&i||l>=i)&&Object.keys(o.O).every((e=>o.O[e](t[s])))?t.splice(s--,1):(a=!1,i<l&&(l=i));if(a){e.splice(p--,1);var c=r();void 0!==c&&(n=c)}}return n}i=i||0;for(var p=e.length;p>0&&e[p-1][2]>i;p--)e[p]=e[p-1];e[p]=[t,r,i]},o.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),(()=>{var e={523:0,966:0};o.O.j=n=>0===e[n];var n=(n,t)=>{var r,i,[l,a,s]=t,c=0;if(l.some((n=>0!==e[n]))){for(r in a)o.o(a,r)&&(o.m[r]=a[r]);if(s)var p=s(o)}for(n&&n(t);c<l.length;c++)i=l[c],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return o.O(p)},t=globalThis.webpackChunkflexible_shipping=globalThis.webpackChunkflexible_shipping||[];t.forEach(n.bind(null,0)),t.push=n.bind(null,t.push.bind(t))})();var r=o.O(void 0,[966],(()=>o(638)));r=o.O(r)})();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -17,6 +17,8 @@ use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayGetParameterValue;
use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayOrConditions;
use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayShippingMethodInstanceSettings;
use FSVendor\Octolize\Tracker\TrackerInitializer;
use FSVendor\Psr\Log\LoggerInterface;
use FSVendor\Psr\Log\NullLogger;
use FSVendor\WPDesk\FS\Compatibility\PluginCompatibility;
use FSVendor\WPDesk\FS\Shipment\ShipmentFunctionality;
use FSVendor\WPDesk\FS\TableRate\Logger\Assets;
@ -37,8 +39,6 @@ use FSVendor\WPDesk\View\Resolver\DirResolver;
use FSVendor\WPDesk\View\Resolver\WPThemeResolver;
use FSVendor\WPDesk\WooCommerce\CurrencySwitchers\FilterConvertersFactory;
use FSVendor\WPDesk\WooCommerce\CurrencySwitchers\ShippingIntegrations;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use WPDesk\FS\Blocks\FreeShipping\FreeShippingBlock;
use WPDesk\FS\Blocks\FreeShipping\FreeShippingStoreEndpointData;
use WPDesk\FS\Helpers\FlexibleShippingMethodsChecker;

View file

@ -1,11 +1,11 @@
<?php
use FSVendor\Psr\Log\LoggerInterface;
use FSVendor\WPDesk\Beacon\Beacon\WooCommerceSettingsFieldsModifier;
use FSVendor\WPDesk\FS\TableRate\Logger\NoticeLogger;
use FSVendor\WPDesk\FS\TableRate\Logger\ShippingMethodLogger;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettingsFactory;
use Psr\Log\LoggerInterface;
use WPDesk\FS\TableRate\Rates\FlexibleShippingRates;
use WPDesk\FS\TableRate\RulesSettingsField;
use WPDesk\FS\TableRate\ShippingMethod\CommonMethodSettings;
@ -276,7 +276,14 @@ class WPDesk_Flexible_Shipping extends WC_Shipping_Method {
* @return false|string
*/
public function generate_shipping_rules_html( $key, $data ) {
$rules_settings = new RulesSettingsField( $key, self::SETTING_METHOD_RULES, $data['title'], $data );
$rules_settings = new RulesSettingsField(
$key,
self::SETTING_METHOD_RULES,
$data['title'],
$data,
null,
$this->instance_settings
);
return $rules_settings->render();
}

View file

@ -37,23 +37,24 @@
"minimum-stability": "stable",
"require": {
"php": ">=7.4",
"psr/log": "^1||^2||^3",
"ext-json": "*",
"wpdesk/wp-wpdesk-fs-shipment-interfaces": "^1.0",
"wpdesk/wp-wpdesk-helper-override": "^1.1",
"ext-json": "*"
"wpdesk/wp-wpdesk-helper-override": "^1.1"
},
"require-dev": {
"10up/wp_mock": "*",
"albertofem/rsync-lib": "^1.0",
"lucatume/wp-browser": "<3.5",
"moneyphp/money": "^3.2.1",
"octolize/flexible-shipping-rules": "^1.3.0",
"octolize/octolize-checkout-block-integration": "^1.1",
"octolize/wp-betterdocs-beacon": "^1.0.2",
"octolize/wp-octolize-brand-assets": "^1.3",
"octolize/wp-octolize-tracker": "^1.3.2",
"octolize/wp-onboarding": "^1.9",
"octolize/wp-shipping-extensions": "^1.8.0",
"octolize/wp-shipping-extensions": "^1.9.0",
"phpunit/phpunit": "^7||^8||^9",
"psr/log": "^1||^2||^3",
"wpdesk/wc-currency-switchers-integrations": "^1.1.2",
"wpdesk/wp-abtesting": "^2.0",
"wpdesk/wp-codeception": "^2.11.1",
@ -67,7 +68,7 @@
"wpdesk/wp-wpdesk-composer": "^3",
"wpdesk/wp-wpdesk-fs-compatibility": "^1.0.0",
"wpdesk/wp-wpdesk-fs-shipment": "^2.4.2",
"wpdesk/wp-wpdesk-fs-table-rate": "^4.3",
"wpdesk/wp-wpdesk-fs-table-rate": "^4.4",
"wpdesk/wp-wpdesk-rating-petition": "^1.6",
"wpdesk/wp-wpdesk-tracker": "^3.1",
"wpdesk/wp-wpdesk-tracker-deactivation": "^2.0.0",

View file

@ -3,15 +3,15 @@
* Plugin Name: Flexible Shipping
* Plugin URI: https://wordpress.org/plugins/flexible-shipping/
* Description: Create additional shipment methods in WooCommerce and enable pricing based on cart weight or total.
* Version: 5.1.3
* Version: 6.0.0
* Author: Octolize
* Author URI: https://octol.io/fs-author
* Text Domain: flexible-shipping
* Domain Path: /lang/
* Requires at least: 6.4
* Tested up to: 6.7
* WC requires at least: 9.2
* WC tested up to: 9.6
* WC requires at least: 9.4
* WC tested up to: 9.8
* Requires PHP: 7.4
*
* Copyright 2017 WP Desk Ltd.
@ -34,7 +34,7 @@
defined( 'ABSPATH' ) || exit;
/* THIS VARIABLE CAN BE CHANGED AUTOMATICALLY */
$plugin_version = '5.1.3';
$plugin_version = '6.0.0';
$plugin_name = 'Flexible Shipping';
$plugin_class_name = Flexible_Shipping_Plugin::class;
@ -61,14 +61,6 @@ $requirements = [
],
];
if ( interface_exists( \Psr\Log\LoggerInterface::class ) || interface_exists( \Psr\Log\LoggerAwareInterface::class ) ) {
interface_exists( \Psr\Log\LoggerAwareInterface::class );
class_exists( \Psr\Log\AbstractLogger::class );
class_exists( \Psr\Log\NullLogger::class );
trait_exists( \Psr\Log\LoggerAwareTrait::class );
trait_exists( \Psr\Log\LoggerTrait::class );
}
add_action(
'before_woocommerce_init',
function () {
@ -78,4 +70,20 @@ add_action(
}
);
add_action( 'plugins_loaded', function() {
$dependent_plugins_versions = [
'FLEXIBLE_SHIPPING_LOCATIONS_VERSION' => '3.0.0',
'FLEXIBLE_SHIPPING_PRO_VERSION' =>'3.0.0',
'FLEXIBLE_SHIPPING_VENDORS_VERSION' => '2.0.0',
'OCTOLIZE_BOX_PACKING_VERSION'=> '2.0.0',
'OCTOLIZE_OCTOLIZE_DISTANCE_BASED_SHIPPING_RATES_VERSION' => '2.0.0',
'OCTOLIZE_DELIVERY_DATE_PICKER_VERSION' => '2.0.0',
];
$psr_not_prefixed = false;
foreach ( $dependent_plugins_versions as $constant_name => $plugins_version ) {
$psr_not_prefixed = $psr_not_prefixed || ( defined( $constant_name ) && version_compare( constant( $constant_name ), $plugins_version, '<' ) );
}
define( 'FLEXIBLE_SHIPPING_PSR_NOT_PREFIXED', $psr_not_prefixed );
} );
require __DIR__ . '/vendor_prefixed/wpdesk/wp-plugin-flow-common/src/plugin-init-php52-free.php';

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@ Donate link: https://octol.io/fs-repo-up
Tags: woocommerce shipping, table rate shipping, woocommerce table rate shipping, advanced shipping, flexible shipping woocommerce
Requires at least: 5.8
Tested up to: 6.7
Stable tag: 5.1.3
Stable tag: 6.0.0
Requires PHP: 7.4
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
@ -238,6 +238,40 @@ If you are upgrading from the old Flexible Shipping version (1.3.2, woo-flexible
== Changelog ==
= 6.0.0 - 2025-03-27 =
* Added the ability to paste JSON with rules table configuration in the shipping method settings
* Added an AI assistant for rules table configuration: https://octol.io/fs-rules-table-ai
* Changed the button layout in the rules table settings
= 5.3.5 - 2025-03-18 =
* Fixed warning in free shipping notice generator
* Fixed additional costs settings not saving with some shipping methods
* Fixed fatal error with Product Feed PRO plugin
= 5.3.4 - 2025-03-10 =
* Added support for WooCommerce 9.8
= 5.3.3 - 2025-02-27 =
* Added shipping method description in block checkout
= 5.3.2 - 2025-02-27 =
* Fixed prefixing Psr\Log library with Delivery Date Picker extension
= 5.3.1 - 2025-02-25 =
* Fixed prefixing Psr\Log library
= 5.3.0 - 2025-02-25 =
* Prefixed Psr\Log library
* Fixed conflicts with plugins and themes using non prefixed Psr\Log library
* Fixed rules table crash with Flexible Shipping Locations Add-On
= 5.2.0 - 2025-01-30 =
* Improved rules table settings REACT component
* Fixed fatal Unsupported operand types: string + float with some shipping methods integration.
= 5.1.4 - 2025-01-22 =
* Added support for WooCommerce 9.7
= 5.1.3 - 2025-01-20 =
* Added support for WooCommerce 9.6

View file

@ -7,7 +7,7 @@
namespace WPDesk\FS\Integration;
use Psr\Log\LoggerInterface;
use FSVendor\Psr\Log\LoggerInterface;
/**
* Provides plugin data for integrations.

View file

@ -26,7 +26,7 @@ class DefaultRulesSettings {
* @return array
*/
private function get_default_settings(): array {
return [
$default_settings = [
[
'conditions' => [
[
@ -37,5 +37,7 @@ class DefaultRulesSettings {
self::NEW_FIELD => true,
],
];
return apply_filters( 'flexible-shipping/shipping-method/default-rules-settings', $default_settings );
}
}

View file

@ -243,6 +243,9 @@ class FreeShippingNoticeGenerator implements Hookable {
* @return bool
*/
private function has_shipping_rate_with_free_shipping( $package_rates ) {
if ( ! is_array( $package_rates ) ) {
return false;
}
/** @var WC_Shipping_Rate $package_rate */
foreach ( $package_rates as $package_rate ) {
if ( $this->is_package_rate_from_flexible_shipping( $package_rate ) ) {

View file

@ -3,7 +3,7 @@
namespace WPDesk\FS\TableRate;
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use Psr\Log\LoggerInterface;
use FSVendor\Psr\Log\LoggerInterface;
/**
* Can convert from shop currency to current currency.

View file

@ -1,212 +0,0 @@
<?php
/**
* Class AbstractCondition
*
* @package WPDesk\FS\TableRate\Rule\Condition
*/
namespace WPDesk\FS\TableRate\Rule\Condition;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\Forms\FieldProvider;
use FSVendor\WPDesk\Forms\Renderer\JsonNormalizedRenderer;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings;
use JsonSerializable;
use Psr\Log\LoggerInterface;
use WPDesk\FS\TableRate\Rule\Rule;
use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
/**
* Abstract condition.
*/
abstract class AbstractCondition implements Condition, FieldProvider, JsonSerializable {
/**
* @var string
*/
protected $condition_id;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $description = '';
/**
* @var string
*/
protected $group;
/**
* @var int
*/
protected $priority = 10;
/**
* @var bool
*/
protected $is_disabled = false;
/**
* @var Rule
*/
protected $rule;
/**
* @return string
*/
public function get_condition_id() {
return $this->condition_id;
}
/**
* @return string
*/
public function get_name() {
return $this->name;
}
/**
* @return string
*/
public function get_description() {
return $this->description;
}
/**
* @return int
*/
public function get_priority() {
return $this->priority;
}
/**
* @return string
*/
public function get_group() {
return $this->group ?: _x( 'General', 'Default Condition Group', 'flexible-shipping' );
}
/**
* @param Rule $rule .
*
* @return self
*/
public function set_rule( Rule $rule ): self {
$this->rule = $rule;
return $this;
}
/**
* @param ShippingContents $shipping_contents .
* @param array $condition_settings .
*
* @return ShippingContents
*/
public function process_shipping_contents( ShippingContents $shipping_contents, array $condition_settings ) {
return $shipping_contents;
}
/**
* @param array $condition_settings .
* @param ShippingContents $contents .
* @param LoggerInterface $logger .
*
* @return bool
*/
public function is_condition_matched( array $condition_settings, ShippingContents $contents, LoggerInterface $logger ) {
return false;
}
/**
* @param array $condition_settings .
* @param ShippingContents $contents .
* @param LoggerInterface $logger .
* @param MethodSettings $method_settings .
*
* @return bool
*/
public function is_condition_matched_with_method_settings( array $condition_settings, ShippingContents $contents, LoggerInterface $logger, MethodSettings $method_settings ) {
return $this->is_condition_matched( $condition_settings, $contents, $logger );
}
/**
* @return Field[]
*/
public function get_fields() {
return [];
}
/**
* @param array $condition_settings .
* @param bool $condition_matched .
* @param string $input_data .
*
* @return string
*/
protected function format_for_log( array $condition_settings, $condition_matched, $input_data ) {
// Translators: condition name.
$formatted_for_log = ' ' . sprintf( __( 'Condition: %1$s;', 'flexible-shipping' ), $this->get_name() );
foreach ( $this->get_fields() as $field ) {
$value = $condition_settings[ $field->get_name() ] ?? '';
if ( $field instanceof Field\SelectField ) {
$options = $field->get_meta_value( 'possible_values' );
foreach ( $options as $option ) {
if ( $option['value'] === $value ) {
$value = $option['label'];
}
}
}
$formatted_for_log .= sprintf( ' %1$s: %2$s;', $field->get_name(), is_array( $value ) ? implode( ', ', $value ) : $value );
}
// Translators: input data.
$formatted_for_log .= sprintf( __( ' input data: %1$s;', 'flexible-shipping' ), $input_data );
// Translators: matched condition.
$formatted_for_log .= sprintf( __( ' matched: %1$s', 'flexible-shipping' ), $condition_matched ? __( 'yes', 'flexible-shipping' ) : __( 'no', 'flexible-shipping' ) );
return $formatted_for_log;
}
/**
* @param array $condition_settings .
*
* @return array
*/
public function prepare_settings( $condition_settings ) {
return $condition_settings;
}
/**
* @return bool
*/
public function is_disabled(): bool {
return $this->is_disabled;
}
/**
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize(): array {
$renderer = new JsonNormalizedRenderer();
return [
'condition_id' => $this->get_condition_id(),
'label' => $this->get_name(),
'group' => $this->get_group(),
'description' => $this->get_description(),
'parameters' => $renderer->render_fields( $this, [] ),
'is_disabled' => $this->is_disabled(),
];
}
}

View file

@ -1,84 +0,0 @@
<?php
/**
* Interface Condition
*
* @package WPDesk\FS\TableRate\Rule\Condition
*/
namespace WPDesk\FS\TableRate\Rule\Condition;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings;
use Psr\Log\LoggerInterface;
use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
/**
* Condition
*/
interface Condition {
/**
* @return string
*/
public function get_condition_id();
/**
* @return string
*/
public function get_name();
/**
* @return string
*/
public function get_description();
/**
* @return string
*/
public function get_group();
/**
* @return int
*/
public function get_priority();
/**
* @param ShippingContents $shipping_contents .
* @param array $condition_settings .
*
* @return ShippingContents
*/
public function process_shipping_contents( ShippingContents $shipping_contents, array $condition_settings );
/**
* @param array $condition_settings .
* @param ShippingContents $contents .
* @param LoggerInterface $logger .
*
* @return bool
*/
public function is_condition_matched( array $condition_settings, ShippingContents $contents, LoggerInterface $logger );
/**
* @param array $condition_settings .
* @param ShippingContents $contents .
* @param LoggerInterface $logger .
* @param MethodSettings $method_settings .
*
* @return bool
*/
public function is_condition_matched_with_method_settings( array $condition_settings, ShippingContents $contents, LoggerInterface $logger, MethodSettings $method_settings );
/**
* @return Field[]
*/
public function get_fields();
/**
* @param array $condition_settings .
*
* @return array
*/
public function prepare_settings( $condition_settings );
}

View file

@ -1,68 +0,0 @@
<?php
/**
* Class None
*
* @package WPDesk\FS\TableRate\Rule\Condition
*/
namespace WPDesk\FS\TableRate\Rule\Condition;
use FSVendor\WPDesk\Forms\Field;
use Psr\Log\LoggerInterface;
use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
/**
* None Condition.
*/
class None extends AbstractCondition {
const CONDITION_ID = 'none';
/**
* None constructor.
*
* @param int $priority .
*/
public function __construct( $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Always', 'flexible-shipping' );
$this->description = __( 'Fixed shipping cost', 'flexible-shipping' );
$this->priority = $priority;
}
/**
* @param array $condition_settings .
* @param ShippingContents $contents .
* @param LoggerInterface $logger .
*
* @return bool
*/
public function is_condition_matched( array $condition_settings, ShippingContents $contents, LoggerInterface $logger ) {
$logger->debug( $this->format_for_log( $condition_settings, true, '' ) );
return true;
}
/**
* @return Field[]
*/
public function get_fields() {
return [];
}
/**
* @param array $condition_settings .
* @param bool $condition_matched .
* @param string $input_data .
*
* @return string
*/
protected function format_for_log( array $condition_settings, $condition_matched, $input_data ) {
// Translators: condition name.
$formatted_for_log = ' ' . sprintf( __( 'Condition: %1$s;', 'flexible-shipping' ), $this->get_name() );
// Translators: matched condition.
$formatted_for_log .= sprintf( __( ' matched: %1$s', 'flexible-shipping' ), $condition_matched ? __( 'yes', 'flexible-shipping' ) : __( 'no', 'flexible-shipping' ) );
return $formatted_for_log;
}
}

View file

@ -14,6 +14,7 @@ use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
/**
* Price condition.
*/
if ( defined( 'FLEXIBLE_SHIPPING_PSR_NOT_PREFIXED' ) && FLEXIBLE_SHIPPING_PSR_NOT_PREFIXED ) {
class Price extends AbstractCondition {
const MIN = 'min';
@ -28,9 +29,9 @@ class Price extends AbstractCondition {
*/
public function __construct( $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Price', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the cart total or package value', 'flexible-shipping' );
$this->group = __( 'Cart', 'flexible-shipping' );
$this->name = __( 'Price', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the cart total or package value', 'flexible-shipping-rules' );
$this->group = __( 'Cart', 'flexible-shipping-rules' );
$this->priority = $priority;
}
@ -87,19 +88,108 @@ class Price extends AbstractCondition {
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'parameter_min' )
->add_data( 'beacon_search', __( 'price is from', 'flexible-shipping' ) )
->set_placeholder( __( 'min', 'flexible-shipping' ) )
->set_label( __( 'is from', 'flexible-shipping' ) ),
->add_data( 'beacon_search', __( 'price is from', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'min', 'flexible-shipping-rules' ) )
->set_label( __( 'is from', 'flexible-shipping-rules' ) ),
( new Field\InputNumberField() )
->set_name( self::MAX )
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'parameter_max' )
->add_data( 'beacon_search', __( 'price to', 'flexible-shipping' ) )
->set_placeholder( __( 'max', 'flexible-shipping' ) )
->set_label( __( 'to', 'flexible-shipping' ) )
->add_data( 'beacon_search', __( 'price to', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'max', 'flexible-shipping-rules' ) )
->set_label( __( 'to', 'flexible-shipping-rules' ) )
->add_data( 'suffix', get_woocommerce_currency_symbol() ),
];
}
}
} else {
class Price extends AbstractCondition {
const MIN = 'min';
const MAX = 'max';
const CONDITION_ID = 'value';
/**
* Price constructor.
*
* @param int $priority .
*/
public function __construct( $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Price', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the cart total or package value', 'flexible-shipping-rules' );
$this->group = __( 'Cart', 'flexible-shipping-rules' );
$this->priority = $priority;
}
/**
* @param array $condition_settings .
* @param ShippingContents $contents .
* @param LoggerInterface $logger .
*
* @return bool
*/
public function is_condition_matched( array $condition_settings, ShippingContents $contents, $logger ) {
$min = (float) ( isset( $condition_settings[ self::MIN ] ) && 0 !== strlen( $condition_settings[ self::MIN ] ) ? $condition_settings[ self::MIN ] : 0 );
$max = (float) ( isset( $condition_settings[ self::MAX ] ) && 0 !== strlen( $condition_settings[ self::MAX ] ) ? $condition_settings[ self::MAX ] : INF );
$min = (float) apply_filters( 'flexible_shipping_value_in_currency', $min, $min );
if ( $max !== INF ) {
$max = (float) apply_filters( 'flexible_shipping_value_in_currency', $max, $max );
}
$contents_cost = $this->get_contents_cost( $contents );
$condition_matched = $contents_cost >= $min && $contents_cost <= $max;
$logger->debug( $this->format_for_log( $condition_settings, $condition_matched, $contents_cost ) );
return $condition_matched;
}
/**
* @param ShippingContents $contents .
*
* @return float
*/
protected function get_contents_cost( ShippingContents $contents ) {
$contents_cost =
/**
* Can modify contents cost passed to Price (value) condition.
*
* @param float $contents_cost Contents cost.
*
* @since 4.1.1
*/
apply_filters( 'flexible-shipping/condition/contents_value', $contents->get_contents_cost() );
return (float) $contents_cost;
}
/**
* @return Field[]
*/
public function get_fields() {
return [
( new Field\InputNumberField() )
->set_name( self::MIN )
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'parameter_min' )
->add_data( 'beacon_search', __( 'price is from', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'min', 'flexible-shipping-rules' ) )
->set_label( __( 'is from', 'flexible-shipping-rules' ) ),
( new Field\InputNumberField() )
->set_name( self::MAX )
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'parameter_max' )
->add_data( 'beacon_search', __( 'price to', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'max', 'flexible-shipping-rules' ) )
->set_label( __( 'to', 'flexible-shipping-rules' ) )
->add_data( 'suffix', get_woocommerce_currency_symbol() ),
];
}
}
}

View file

@ -23,11 +23,11 @@ class CartLineItem extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Cart line item', 'flexible-shipping' );
$this->group = __( 'Cart', 'flexible-shipping' );
$this->name = __( 'Cart line item', 'flexible-shipping-rules' );
$this->group = __( 'Cart', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -21,11 +21,11 @@ class DayOfTheWeek extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Day of the week', 'flexible-shipping' );
$this->group = __( 'Destination & Time', 'flexible-shipping' );
$this->name = __( 'Day of the week', 'flexible-shipping-rules' );
$this->group = __( 'Destination & Time', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -21,11 +21,11 @@ class DimensionalWeight extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Dimensional weight', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Dimensional weight', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -21,11 +21,11 @@ class Item extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Item', 'flexible-shipping' );
$this->group = __( 'Cart', 'flexible-shipping' );
$this->name = __( 'Item', 'flexible-shipping-rules' );
$this->group = __( 'Cart', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -21,12 +21,12 @@ class MaxDimension extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Max dimension', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the product\'s maximum dimension', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Max dimension', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the product\'s maximum dimension', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -23,11 +23,11 @@ class Product extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Product', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Product', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -23,11 +23,11 @@ class ProductCategory extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Product category', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Product category', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -18,12 +18,12 @@ class ProductDimensionHeight extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Height', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the product\'s height', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Height', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the product\'s height', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -18,12 +18,12 @@ class ProductDimensionLength extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Length', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the product\'s length', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Length', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the product\'s length', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -18,12 +18,12 @@ class ProductDimensionWidth extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Width', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the product\'s width', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Width', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the product\'s width', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -12,12 +12,12 @@ class ProductFieldRange extends AbstractCondition {
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Field range', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the product\'s field range', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Field range', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the product\'s field range', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -10,13 +10,13 @@ class ProductFieldValue extends AbstractCondition {
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Field value', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the product\'s field value', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Field value', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the product\'s field value', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -13,12 +13,12 @@ class ProductStockQuantity extends AbstractCondition {
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Stock quantity', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the product\'s stock quantity', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Stock quantity', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the product\'s stock quantity', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -10,12 +10,12 @@ class ProductStockStatus extends AbstractCondition {
public function __construct( array $stock_status_options, int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Stock status', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the product\'s stock status', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Stock status', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the product\'s stock status', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -23,11 +23,11 @@ class ProductTag extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Product tag', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Product tag', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -21,11 +21,11 @@ class ShippingClass extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Shipping class', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Shipping class', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -14,11 +14,11 @@ class ShippingCost extends AbstractCondition {
public function __construct( $priority = 10 ) {
$this->priority = $priority;
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Shipping cost', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on current shipping cost', 'flexible-shipping' );
$this->group = __( 'Shipping', 'flexible-shipping' );
$this->name = __( 'Shipping cost', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on current shipping cost', 'flexible-shipping-rules' );
$this->group = __( 'Shipping', 'flexible-shipping-rules' );
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -21,11 +21,11 @@ class TimeOfTheDay extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Time of the day', 'flexible-shipping' );
$this->group = __( 'Destination & Time', 'flexible-shipping' );
$this->name = __( 'Time of the day', 'flexible-shipping-rules' );
$this->group = __( 'Destination & Time', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -23,11 +23,11 @@ class TotalOverallDimensions extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Total overall dimensions', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Total overall dimensions', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -21,11 +21,11 @@ class UserRole extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'User Role', 'flexible-shipping' );
$this->group = __( 'User', 'flexible-shipping' );
$this->name = __( 'User Role', 'flexible-shipping-rules' );
$this->group = __( 'User', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -21,11 +21,11 @@ class Volume extends AbstractCondition {
*/
public function __construct( int $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Volume', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Volume', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
$this->is_disabled = true;
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping' );
$this->name .= ' ' . __( '(PRO feature)', 'flexible-shipping-rules' );
}
}

View file

@ -14,6 +14,7 @@ use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
/**
* Weight condition.
*/
if ( defined( 'FLEXIBLE_SHIPPING_PSR_NOT_PREFIXED' ) && FLEXIBLE_SHIPPING_PSR_NOT_PREFIXED ) {
class Weight extends AbstractCondition {
const MIN = 'min';
@ -28,9 +29,9 @@ class Weight extends AbstractCondition {
*/
public function __construct( $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Weight', 'flexible-shipping' );
$this->description = __( 'Shipping cost based on the weight of the cart or package', 'flexible-shipping' );
$this->group = __( 'Product', 'flexible-shipping' );
$this->name = __( 'Weight', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the weight of the cart or package', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
}
@ -74,19 +75,95 @@ class Weight extends AbstractCondition {
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'parameter_min' )
->add_data( 'beacon_search', __( 'weight is from', 'flexible-shipping' ) )
->set_placeholder( __( 'is from', 'flexible-shipping' ) )
->set_label( __( 'is from', 'flexible-shipping' ) ),
->add_data( 'beacon_search', __( 'weight is from', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'is from', 'flexible-shipping-rules' ) )
->set_label( __( 'is from', 'flexible-shipping-rules' ) ),
( new Field\InputNumberField() )
->set_name( self::MAX )
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'parameter_max' )
->add_data( 'beacon_search', __( 'weight to', 'flexible-shipping' ) )
->set_placeholder( __( 'to', 'flexible-shipping' ) )
->set_label( __( 'to', 'flexible-shipping' ) )
->add_data( 'beacon_search', __( 'weight to', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'to', 'flexible-shipping-rules' ) )
->set_label( __( 'to', 'flexible-shipping-rules' ) )
->add_data( 'suffix', get_option( 'woocommerce_weight_unit' ) ),
];
}
}
} else {
class Weight extends AbstractCondition {
const MIN = 'min';
const MAX = 'max';
const CONDITION_ID = 'weight';
/**
* Weight constructor.
*
* @param int $priority .
*/
public function __construct( $priority = 10 ) {
$this->condition_id = self::CONDITION_ID;
$this->name = __( 'Weight', 'flexible-shipping-rules' );
$this->description = __( 'Shipping cost based on the weight of the cart or package', 'flexible-shipping-rules' );
$this->group = __( 'Product', 'flexible-shipping-rules' );
$this->priority = $priority;
}
/**
* @param array $condition_settings .
* @param ShippingContents $contents .
* @param LoggerInterface $logger .
*
* @return bool
*/
public function is_condition_matched( array $condition_settings, ShippingContents $contents, $logger ) {
$min = (float) ( isset( $condition_settings[ self::MIN ] ) && 0 !== strlen( $condition_settings[ self::MIN ] ) ? $condition_settings[ self::MIN ] : 0 );
$max = (float) ( isset( $condition_settings[ self::MAX ] ) && 0 !== strlen( $condition_settings[ self::MAX ] ) ? $condition_settings[ self::MAX ] : INF );
$contents_weight =
/**
* Can modify contents weight passed to Weight condition.
*
* @param float $contents_weight Contents weight.
*
* @since 4.1.1
*/
apply_filters( 'flexible-shipping/condition/contents_weight', $contents->get_contents_weight() );
$contents_weight = (float) $contents_weight;
$condition_matched = $contents_weight >= $min && $contents_weight <= $max;
$logger->debug( $this->format_for_log( $condition_settings, $condition_matched, $contents_weight ) );
return $condition_matched;
}
/**
* @return Field[]
*/
public function get_fields() {
return [
( new Field\InputNumberField() )
->set_name( self::MIN )
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'parameter_min' )
->add_data( 'beacon_search', __( 'weight is from', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'is from', 'flexible-shipping-rules' ) )
->set_label( __( 'is from', 'flexible-shipping-rules' ) ),
( new Field\InputNumberField() )
->set_name( self::MAX )
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'parameter_max' )
->add_data( 'beacon_search', __( 'weight to', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'to', 'flexible-shipping-rules' ) )
->set_label( __( 'to', 'flexible-shipping-rules' ) )
->add_data( 'suffix', get_option( 'woocommerce_weight_unit' ) ),
];
}
}
}

View file

@ -1,24 +0,0 @@
<?php
/**
* Interface ContentsFilter
*
* @package WPDesk\FS\TableRate\Rule
*/
namespace WPDesk\FS\TableRate\Rule;
/**
* Contents filter interface.
*/
interface ContentsFilter {
/**
* Returns filtered contents.
*
* @param array $contents .
*
* @return array
*/
public function get_filtered_contents( array $contents );
}

View file

@ -1,175 +0,0 @@
<?php
/**
* Class AbstractAdditionalCost
*
* @package WPDesk\FS\TableRate\Rule\Cost
*/
namespace WPDesk\FS\TableRate\Rule\Cost;
use FSVendor\WPDesk\Forms\Renderer\JsonNormalizedRenderer;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings;
use JsonSerializable;
use Psr\Log\LoggerInterface;
use Throwable;
use WPDesk\FS\TableRate\Rule\Rule;
use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
use function Patchwork\Config\locate;
/**
* Abstract Additional Cost.
*/
abstract class AbstractAdditionalCost implements AdditionalCost, JsonSerializable {
/**
* @var string
*/
protected $based_on;
/**
* @var string
*/
protected $name;
/**
* @var MethodSettings
*/
protected $method_settings;
/**
* @var Rule
*/
protected $rule;
/**
* @return string
*/
public function get_based_on() {
return $this->based_on;
}
/**
* @return string
*/
public function get_name() {
return $this->name;
}
/**
* @param array $additional_cost_settings .
*
* @return float|null
*/
public function get_per_value( array $additional_cost_settings ) {
$setting_value = $this->get_settings_value( RuleAdditionalCostFieldsFactory::PER_VALUE, $additional_cost_settings );
return isset( $setting_value ) ? (float) $setting_value : null;
}
/**
* @param array $additional_cost_settings .
*
* @return float|null
*/
public function get_additional_cost( array $additional_cost_settings ) {
$setting_value = $this->get_settings_value( RuleAdditionalCostFieldsFactory::ADDITIONAL_COST, $additional_cost_settings );
return isset( $setting_value ) ? (float) $setting_value : null;
}
/**
* @param string $name .
* @param array $settings .
*/
private function get_settings_value( $name, array $settings ) {
return isset( $settings[ $name ] ) ? $settings[ $name ] : null;
}
/**
* @param ShippingContents $shipping_contents .
* @param array $additional_cost_settings .
* @param LoggerInterface $logger .
*
* @return float
*/
public function calculate_cost( ShippingContents $shipping_contents, array $additional_cost_settings, LoggerInterface $logger ) {
try {
$per_value = $this->get_per_value( $additional_cost_settings );
$additional_cost = $this->get_additional_cost( $additional_cost_settings );
// Tricky fix (float->string->float) for bug in rounding (#OCT-2684).
$shipment_contents_value = (float) (string) $this->get_value_from_shipment_contents( $shipping_contents );
if ( isset( $per_value, $additional_cost ) && 0.0 !== $per_value ) {
$calculated_additional_cost = ceil( $shipment_contents_value / $per_value ) * $additional_cost;
} else {
$calculated_additional_cost = 0;
}
$logger->debug(
sprintf(
' %1$s %2$s; %3$s; %4$s; %5$s',
__( 'additional cost:', 'flexible-shipping' ),
// Translators: cost per.
sprintf( __( '%1$s per %2$s', 'flexible-shipping' ), $additional_cost, $per_value ),
// Translators: based on.
sprintf( __( 'based on: %1$s', 'flexible-shipping' ), $this->get_name() ),
// Translators: input data.
sprintf( __( 'input data: %1$s', 'flexible-shipping' ), $shipment_contents_value ),
// Translators: calculated.
sprintf( __( 'calculated: %1$s', 'flexible-shipping' ), $calculated_additional_cost )
)
);
} catch ( Throwable $e ) {
$logger->debug( $e->getMessage() );
$calculated_additional_cost = 0;
}
return $calculated_additional_cost;
}
/**
* @param ShippingContents $shipping_contents .
* @param array $additional_cost_settings .
* @param LoggerInterface $logger .
* @param MethodSettings $method_settings .
*
* @return float
*/
public function calculate_cost_with_method_settings( ShippingContents $shipping_contents, array $additional_cost_settings, LoggerInterface $logger, MethodSettings $method_settings ) {
$this->method_settings = $method_settings;
return $this->calculate_cost( $shipping_contents, $additional_cost_settings, $logger );
}
/**
* @param Rule $rule
*
* @return $this
*/
public function set_rule( Rule $rule ): AbstractAdditionalCost {
$this->rule = $rule;
return $this;
}
/**
* Returns value from shipment contents to calculate cost.
*
* @param ShippingContents $shipping_contents .
*
* @return float
*/
abstract protected function get_value_from_shipment_contents( $shipping_contents );
/**
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize(): array {
$renderer = new JsonNormalizedRenderer();
return [
'additional_cost_id' => $this->get_based_on(),
'label' => $this->get_name(),
'parameters' => $renderer->render_fields( $this, [] ),
];
}
}

View file

@ -1,49 +0,0 @@
<?php
/**
* Interface AdditionalCost
*
* @package WPDesk\FS\TableRate\Rule\Cost
*/
namespace WPDesk\FS\TableRate\Rule\Cost;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\Forms\FieldProvider;
use Psr\Log\LoggerInterface;
use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings;
/**
* Additional Costs Interface.
*/
interface AdditionalCost {
/**
* @return string
*/
public function get_based_on();
/**
* @return string
*/
public function get_name();
/**
* @param ShippingContents $shipping_contents .
* @param array $additional_cost_settings .
* @param LoggerInterface $logger .
*
* @return float
*/
public function calculate_cost( ShippingContents $shipping_contents, array $additional_cost_settings, LoggerInterface $logger );
/**
* @param ShippingContents $shipping_contents .
* @param array $additional_cost_settings .
* @param LoggerInterface $logger .
* @param MethodSettings $method_settings .
*
* @return float
*/
public function calculate_cost_with_method_settings( ShippingContents $shipping_contents, array $additional_cost_settings, LoggerInterface $logger, MethodSettings $method_settings );
}

View file

@ -7,12 +7,12 @@
namespace WPDesk\FS\TableRate\Rule\Cost;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\Forms\Field\InputTextField;
use FSVendor\WPDesk\Forms\FieldProvider;
use FSVendor\WPDesk\Forms\Renderer\JsonNormalizedRenderer;
/**
* Can create additional costs fields.
*/
@ -66,25 +66,25 @@ class RuleAdditionalCostFieldsFactory implements FieldProvider {
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'additional-cost-cost' )
->add_data( 'beacon_search', __( 'additional cost', 'flexible-shipping' ) )
->set_placeholder( __( 'additional cost', 'flexible-shipping' ) )
->set_label( __( 'additional cost is', 'flexible-shipping' ) )
->add_data( 'beacon_search', __( 'additional cost', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'additional cost', 'flexible-shipping-rules' ) )
->set_label( __( 'additional cost is', 'flexible-shipping-rules' ) )
->add_data( 'suffix', get_woocommerce_currency_symbol() ),
( new Field\InputNumberField() )
->set_name( self::PER_VALUE )
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'additional-cost-per' )
->add_data( 'beacon_search', __( 'additional cost per', 'flexible-shipping' ) )
->set_placeholder( __( 'per', 'flexible-shipping' ) )
->set_label( __( 'per', 'flexible-shipping' ) ),
->add_data( 'beacon_search', __( 'additional cost per', 'flexible-shipping-rules' ) )
->set_placeholder( __( 'per', 'flexible-shipping-rules' ) )
->set_label( __( 'per', 'flexible-shipping-rules' ) ),
( new Field\SelectField() )
->set_name( self::BASED_ON )
->set_options( $this->get_based_on_options() )
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'additional-cost-based-on' )
->add_data( 'beacon_search', __( 'additional cost per', 'flexible-shipping' ) ),
->add_data( 'beacon_search', __( 'additional cost per', 'flexible-shipping-rules' ) ),
);
}

View file

@ -7,8 +7,8 @@
namespace WPDesk\FS\TableRate\Rule\Cost;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\Forms\FieldProvider;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\Forms\Renderer\JsonNormalizedRenderer;
/**
@ -47,9 +47,9 @@ class RuleCostFieldsFactory implements FieldProvider {
->add_class( 'wc_input_decimal' )
->add_class( 'hs-beacon-search' )
->add_class( 'cost_per_order' )
->add_data( 'beacon_search', __( 'Cost per order', 'flexible-shipping' ) )
->set_label( __( 'rule cost is', 'flexible-shipping' ) )
->set_description_tip( __( 'Enter shipment cost for this rule.', 'flexible-shipping' ) )
->add_data( 'beacon_search', __( 'Cost per order', 'flexible-shipping-rules' ) )
->set_label( __( 'rule cost is', 'flexible-shipping-rules' ) )
->set_description_tip( __( 'Enter shipment cost for this rule.', 'flexible-shipping-rules' ) )
->add_data( 'suffix', get_woocommerce_currency_symbol() ),
);
}

View file

@ -1,284 +0,0 @@
<?php
/**
* Class CostsCalculator
*
* @package WPDesk\FS\TableRate\Rule
*/
namespace WPDesk\FS\TableRate\Rule;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\FS\TableRate\Logger\ArrayLogger;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings;
use Psr\Log\LoggerInterface;
use WC_Cart;
use WPDesk\FS\TableRate\Rule;
use WPDesk\FS\TableRate\Rule\Condition\Weight;
use WPDesk\FS\TableRate\Rule\Condition\ConditionsFactory;
use WPDesk\FS\TableRate\Rule\Cost\AdditionalCost;
use WPDesk\FS\TableRate\Rule\RoundingPrecision;
use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
use WPDesk\FS\TableRate\Rule\SpecialAction\SpecialAction;
use WPDesk\FS\TableRate\RulesSettingsFactory;
/**
* Can calculate shipping costs.
*/
class CostsCalculator {
/**
* @var MethodSettings
*/
private $method_settings;
/**
* @var Rule\Rule[]
*/
private $prepared_rules = [];
/**
* @var float
*/
private $calculated_cost = 0.0;
/**
* @var bool
*/
private $is_triggered = false;
/**
* @var bool
*/
private bool $is_cancel = false;
/**
* @var Rule\Condition\Condition[]
*/
private $available_conditions;
/**
* @var Field[]
*/
private $cost_fields;
/**
* @var AdditionalCost[]
*/
private $available_additional_costs;
/**
* @var SpecialAction[]
*/
private $available_special_actions;
/**
* @var int
*/
private $cost_rounding_precision;
/**
* @var ShippingContents
*/
private $shipping_contents;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var string
*/
private $shop_currency;
/**
* CostsCalculator constructor.
*
* @param MethodSettings $method_settings .
* @param ShippingContents $shipping_contents .
* @param Rule\Condition\Condition[] $available_conditions .
* @param Field[] $cost_fields .
* @param AdditionalCost[] $available_additional_costs .
* @param SpecialAction[] $available_special_actions .
* @param int $cost_rounding_precision .
* @param string $shop_currency .
* @param LoggerInterface $logger .
*/
public function __construct(
MethodSettings $method_settings,
ShippingContents $shipping_contents,
array $available_conditions,
$cost_fields,
$available_additional_costs,
$available_special_actions,
$cost_rounding_precision,
$shop_currency,
$logger
) {
$this->method_settings = $method_settings;
$this->shipping_contents = $shipping_contents;
$this->available_conditions = $available_conditions;
$this->cost_fields = $cost_fields;
$this->available_additional_costs = $available_additional_costs;
$this->available_special_actions = $available_special_actions;
$this->cost_rounding_precision = $cost_rounding_precision;
$this->shop_currency = $shop_currency;
$this->logger = $logger;
$this->prepared_rules = $this->prepare_rules();
}
/**
* .
*/
public function process_rules( $calculated_cost = null ) {
$this->shipping_contents->set_weight_rounding_precision( $this->calculate_weight_rounding_precision( $this->prepared_rules ) );
$this->calculated_cost = $this->calculate_cost( $calculated_cost );
}
/**
* @return Rule\Rule[]
*/
private function prepare_rules() {
$prepared_rules = [];
foreach ( $this->get_rules_settings() as $rule_settings ) {
$prepared_rules[] = new Rule\Rule(
$rule_settings,
$this->available_conditions,
$this->cost_fields,
$this->available_additional_costs,
$this->available_special_actions,
$this->cost_rounding_precision,
$this->method_settings
);
}
return $prepared_rules;
}
/**
* @return array
*/
private function get_rules_settings() {
$rules_settings = $this->method_settings->get_rules_settings();
$settings = RulesSettingsFactory::create_from_array( $rules_settings );
return $settings->get_normalized_settings();
}
/**
* @param float $calculated_cost .
* @param float $rule_cost .
*
* @return float
*
* @internal
*/
public function sum_calculation( $calculated_cost, $rule_cost ) {
if ( null === $calculated_cost ) {
$calculated_cost = 0.0;
}
return $calculated_cost + $rule_cost;
}
/**
* @return float
*/
private function calculate_cost( $calculated_cost = null ): float {
/**
* Rules calculation function.
* Default rules calculation is sum.
*
* @param callback $callbac Callback function.
* @param string $callback_setting Callback setting.
*/
$calculation_method_callback = apply_filters(
'flexible-shipping/shipping-method/rules-calculation-function',
[ $this, 'sum_calculation' ],
$this->method_settings->get_calculation_method()
);
$this->shipping_contents->reset_contents();
$this->shipping_contents->set_calculated_shipping_cost( (float) ( $calculated_cost ?? 0.0 ) );
foreach ( $this->prepared_rules as $rule_index => $calculated_rule ) {
$this->shipping_contents = $calculated_rule->process_shipping_contents( $this->shipping_contents );
$rule_cost = 0.0;
$rule_logger = new ArrayLogger();
$is_rule_triggered = false;
if ( $calculated_rule->is_rule_triggered( $this->shipping_contents, $rule_logger ) ) {
$is_rule_triggered = true;
$this->is_triggered = true;
$rule_cost = $calculated_rule->get_rule_cost( $this->shipping_contents, $rule_logger );
$calculated_cost = $calculation_method_callback( $calculated_cost, $rule_cost );
$this->shipping_contents->set_calculated_shipping_cost( $calculated_cost );
}
$this->logger->debug( $calculated_rule->format_for_log( $rule_index + 1 ), $this->logger->get_rule_context( $is_rule_triggered ) );
$this->logger->log_from_array_logger( $rule_logger, $this->logger->get_rule_context( $is_rule_triggered ) );
if ( $is_rule_triggered ) {
$this->logger->debug(
// Translators: rule cost.
sprintf( ' ' . __( 'Calculated rule cost: %1$s %2$s', 'flexible-shipping' ), $rule_cost, $this->shop_currency ),
$this->logger->get_rule_context( $is_rule_triggered )
);
$special_action = $calculated_rule->get_special_action();
if ( $special_action->is_stop() ) {
break;
}
if ( $special_action->is_cancel() ) {
$this->is_cancel = true;
$this->is_triggered = false;
break;
}
}
$this->shipping_contents->reset_contents();
}
if ( null === $calculated_cost ) {
$calculated_cost = 0.0;
}
/**
* Calculated shipping method cost.
*
* @param float $calculated_cost Calculated cost.
* @param array $shipping_method_settings Current shipping method settings.
*/
return (float) apply_filters( 'flexible-shipping/shipping-method/calculated-cost', $calculated_cost, $this->method_settings->get_raw_settings() );
}
/**
* @param Rule\Rule[] $prepared_rules .
*
* @return int
*/
private function calculate_weight_rounding_precision( array $prepared_rules ) {
$rounding_precision = new RoundingPrecision( $prepared_rules, $this->available_conditions );
return $rounding_precision->calculate_max_precision_for_condition( Weight::CONDITION_ID );
}
/**
* @return float
*/
public function get_calculated_cost() {
return $this->calculated_cost;
}
/**
* @return bool
*/
public function is_triggered() {
return $this->is_triggered;
}
/**
* @return bool
*/
public function is_cancel() {
return $this->is_cancel;
}
}

View file

@ -33,9 +33,9 @@ class PreconfiguredScenariosFactory {
$pl = get_locale() === 'pl_PL';
$url = $pl ? 'https://octol.io/fs-weight-pl' : 'https://octol.io/fs-weight';
$scenarios['simple_weight'] = new PredefinedScenario(
__( 'Weight', 'flexible-shipping' ),
__( 'Weight-based shipping', 'flexible-shipping' ),
__( 'Shipping cost increases in line with the cart total weight.', 'flexible-shipping' ),
__( 'Weight', 'flexible-shipping-rules' ),
__( 'Weight-based shipping', 'flexible-shipping-rules' ),
__( 'Shipping cost increases in line with the cart total weight.', 'flexible-shipping-rules' ),
$url,
'[{"conditions":[{"condition_id":"weight","min":"","max":"0.999"}],"cost_per_order":"10","additional_costs":[],"special_action":""},{"conditions":[{"condition_id":"weight","min":"1","max":"3.999"}],"cost_per_order":"11","additional_costs":[],"special_action":""},{"conditions":[{"condition_id":"weight","min":"4","max":"6.999"}],"cost_per_order":"12","additional_costs":[],"special_action":""},{"conditions":[{"condition_id":"weight","min":"7","max":"10"}],"cost_per_order":"13","additional_costs":[],"special_action":""}]'
);
@ -52,9 +52,9 @@ class PreconfiguredScenariosFactory {
$pl = get_locale() === 'pl_PL';
$url = $pl ? 'https://octol.io/fs-price-based-pl' : 'https://octol.io/fs-price-based';
$scenarios['simple_value'] = new PredefinedScenario(
__( 'Price', 'flexible-shipping' ),
__( 'Price-based shipping', 'flexible-shipping' ),
__( 'Shipping cost decreases in line with the cart total. Free shipping once $300 threshold is reached.', 'flexible-shipping' ),
__( 'Price', 'flexible-shipping-rules' ),
__( 'Price-based shipping', 'flexible-shipping-rules' ),
__( 'Shipping cost decreases in line with the cart total. Free shipping once $300 threshold is reached.', 'flexible-shipping-rules' ),
$url,
'[{"conditions":[{"condition_id":"value","min":"","max":"99.99"}],"cost_per_order":"20","additional_costs":[],"special_action":"none"},{"conditions":[{"condition_id":"value","min":"100","max":"199.99"}],"cost_per_order":"15","additional_costs":[],"special_action":"none"},{"conditions":[{"condition_id":"value","min":"200","max":"299.99"}],"cost_per_order":"10","additional_costs":[],"special_action":"none"},{"conditions":[{"condition_id":"value","min":"300","max":""}],"cost_per_order":"0","additional_costs":[],"special_action":"none"}]'
);

View file

@ -1,106 +0,0 @@
<?php
/**
* Class RoundingPrecision
*
* @package WPDesk\FS\TableRate\Rule
*/
namespace WPDesk\FS\TableRate\Rule;
use WPDesk\FS\TableRate\Rule\Condition\Condition;
use WPDesk\FS\TableRate\Rule\Condition\Weight;
/**
* Can calculate rounding precision from conditions settings.
*/
class RoundingPrecision {
const CONDITION_ID = 'condition_id';
/**
* @var Rule[]
*/
private $rules;
/**
* @var Condition[]
*/
private $available_conditions;
/**
* @param Rule[] $rules .
* @param Condition[] $available_conditions .
*/
public function __construct( array $rules, array $available_conditions ) {
$this->rules = $rules;
$this->available_conditions = $available_conditions;
}
/**
* @param string $condition_id .
*/
public function calculate_max_precision_for_condition( $condition_id ) {
$max_precision = 0;
foreach ( $this->rules as $prepared_rule ) {
$max_precision = max( $max_precision, $this->get_max_precision_for_conditions( $prepared_rule, $condition_id ) );
}
return $max_precision;
}
/**
* @param Rule $prepared_rule .
* @param string $condition_id .
*
* @return int
*/
private function get_max_precision_for_conditions( $prepared_rule, $condition_id ) {
$max_precision = 0;
if ( $prepared_rule->has_rule_conditions() ) {
$rule_settings = $prepared_rule->get_rules_settings();
foreach ( $rule_settings['conditions'] as $condition_settings ) {
$max_precision = max( $max_precision, $this->get_max_precision_for_single_condition( $condition_settings, $condition_id ) );
}
}
return $max_precision;
}
/**
* @param array $condition_settings .
* @param string $condition_id .
*
* @return int mixed
*/
private function get_max_precision_for_single_condition( $condition_settings, $condition_id ) {
$max_precision = 0;
if ( isset( $condition_settings[ self::CONDITION_ID ], $this->available_conditions[ $condition_settings[ self::CONDITION_ID ] ] )
&& $condition_id === $condition_settings[ self::CONDITION_ID ]
) {
foreach ( $this->available_conditions[ $condition_settings[ self::CONDITION_ID ] ]->get_fields() as $field ) {
$max_precision = max( $max_precision, $this->get_precision_for_field( $condition_settings, $field->get_name() ) );
}
}
return $max_precision;
}
/**
* @param array $condition_settings .
* @param string $field_name .
*
* @return int
*/
private function get_precision_for_field( $condition_settings, $field_name ) {
$field_precision = 0;
if ( isset( $condition_settings[ $field_name ] ) ) {
$parts = explode( '.', $condition_settings[ $field_name ] );
$field_precision = 0;
if ( isset( $parts[1] ) ) {
$field_precision = strlen( $parts[1] );
}
}
return $field_precision;
}
}

View file

@ -1,247 +0,0 @@
<?php
/**
* Class Rule
*
* @package WPDesk\FS\TableRate\Calculate
*/
namespace WPDesk\FS\TableRate\Rule;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings;
use Psr\Log\LoggerInterface;
use WPDesk\FS\TableRate\Rule\Condition\AbstractCondition;
use WPDesk\FS\TableRate\Rule\Condition\Condition;
use WPDesk\FS\TableRate\Rule\Cost\AbstractAdditionalCost;
use WPDesk\FS\TableRate\Rule\Cost\AdditionalCost;
use WPDesk\FS\TableRate\Rule\ShippingContents\ShippingContents;
use WPDesk\FS\TableRate\Rule\SpecialAction\None;
use WPDesk\FS\TableRate\Rule\SpecialAction\SpecialAction;
/**
* Single rule.
*/
class Rule {
const CONDITION_ID = 'condition_id';
const CONDITIONS = 'conditions';
const ADDITIONAL_COSTS = 'additional_costs';
const SPECIAL_ACTION = 'special_action';
/**
* @var array
*/
private $rule_settings;
/**
* @var Condition[]
*/
private $available_conditions;
/**
* @var Field[]
*/
private $cost_fields;
/**
* @var AdditionalCost[]
*/
private $available_additional_costs;
/**
* @var SpecialAction[]
*/
private $available_special_actions;
/**
* @var int
*/
private $cost_rounding_precision;
/**
* @var MethodSettings
*/
private $method_settings;
/**
* Rule constructor.
*
* @param array $rule_settings .
* @param Condition[] $available_conditions .
* @param Field[] $cost_fields .
* @param AdditionalCost[] $available_additional_costs .
* @param SpecialAction[] $available_special_actions .
* @param int $cost_rounding_precision .
* @param MethodSettings $method_settings .
*/
public function __construct(
$rule_settings,
array $available_conditions,
array $cost_fields,
array $available_additional_costs,
array $available_special_actions,
$cost_rounding_precision,
MethodSettings $method_settings
) {
$this->rule_settings = $rule_settings;
$this->available_conditions = $available_conditions;
$this->cost_fields = $cost_fields;
$this->available_additional_costs = $available_additional_costs;
$this->available_special_actions = $available_special_actions;
$this->cost_rounding_precision = $cost_rounding_precision;
$this->method_settings = $method_settings;
}
/**
* @param ShippingContents $shipping_contents .
*
* @return ShippingContents
*/
public function process_shipping_contents( ShippingContents $shipping_contents ): ShippingContents {
if ( $this->has_rule_conditions() ) {
foreach ( $this->rule_settings[ self::CONDITIONS ] as $condition_settings_key => $condition_settings ) {
if ( isset( $condition_settings[ self::CONDITION_ID ], $this->available_conditions[ $condition_settings[ self::CONDITION_ID ] ] ) ) {
$condition = $this->available_conditions[ $condition_settings[ self::CONDITION_ID ] ];
$shipping_contents = $condition->process_shipping_contents( $shipping_contents, $condition_settings );
}
}
}
return $shipping_contents;
}
/**
* @param ShippingContents $shipping_contents .
* @param LoggerInterface $logger .
*
* @return bool
*/
public function is_rule_triggered( ShippingContents $shipping_contents, LoggerInterface $logger ): bool {
$triggered = true;
if ( $this->has_rule_conditions() ) {
foreach ( $this->rule_settings[ self::CONDITIONS ] as $condition_settings_key => $condition_settings ) {
if ( isset( $condition_settings[ self::CONDITION_ID ], $this->available_conditions[ $condition_settings[ self::CONDITION_ID ] ] ) ) {
/** @var AbstractCondition $condition */
$condition = $this->available_conditions[ $condition_settings[ self::CONDITION_ID ] ];
$condition->set_rule( $this );
$condition_triggered = $condition->is_condition_matched_with_method_settings( $condition_settings, $shipping_contents, $logger, $this->method_settings );
$triggered = $triggered && $condition_triggered;
}
if ( ! $triggered ) {
break;
}
}
}
return $triggered;
}
/**
* @return bool
*/
public function has_rule_conditions(): bool {
return isset( $this->rule_settings[ self::CONDITIONS ] );
}
/**
* @param ShippingContents $shipping_contents .
* @param LoggerInterface $logger .
*
* @return float
*/
public function get_rule_cost( ShippingContents $shipping_contents, LoggerInterface $logger ): float {
// Translators: items.
$logger->debug( sprintf( __( ' Matched items: %1$s', 'flexible-shipping' ), $this->format_contents_for_log( $shipping_contents ) ) );
// Translators: items costs.
$logger->debug( sprintf( __( ' Matched items cost: %1$d %2$s', 'flexible-shipping' ), $shipping_contents->get_contents_cost(), $shipping_contents->get_currency() ) );
// Translators: items weight.
$logger->debug( sprintf( __( ' Matched items weight: %1$s', 'flexible-shipping' ), wc_format_weight( $shipping_contents->get_contents_weight() ) ) );
$logger->debug( sprintf( ' %1$s', __( 'Rule costs:', 'flexible-shipping' ) ) );
$cost = 0.0;
foreach ( $this->cost_fields as $cost_field ) {
if ( isset( $this->rule_settings[ $cost_field->get_name() ] ) ) {
$field_cost = (float) $this->rule_settings[ $cost_field->get_name() ];
$logger->debug( sprintf( ' %1$s: %2$s', $cost_field->get_label(), $field_cost ) );
$cost += $field_cost;
}
}
$cost += $this->get_additional_costs( $shipping_contents, $logger );
return $cost;
}
/**
* @param ShippingContents $shipping_contents
*
* @return string
*/
private function format_contents_for_log( ShippingContents $shipping_contents ): string {
$formatted_contents = [];
foreach ( $shipping_contents->get_contents() as $item ) {
$formatted_contents[] = sprintf( '%1$s (qty: %2$d)', $item['data']->get_name(), $item['quantity'] );
}
return implode( ', ', $formatted_contents );
}
/**
* @return SpecialAction
*/
public function get_special_action() {
if ( isset( $this->rule_settings[ self::SPECIAL_ACTION ], $this->available_special_actions[ $this->rule_settings[ self::SPECIAL_ACTION ] ] ) ) {
return $this->available_special_actions[ $this->rule_settings[ self::SPECIAL_ACTION ] ];
}
return new None();
}
/**
* @param ShippingContents $shipping_contents .
* @param LoggerInterface $logger .
*
* @return float
*/
private function get_additional_costs( ShippingContents $shipping_contents, LoggerInterface $logger ): float {
$additional_costs = 0.0;
$additional_costs_settings = $this->rule_settings[ self::ADDITIONAL_COSTS ] ?? [];
foreach ( $additional_costs_settings as $additional_cost_setting ) {
if ( isset( $this->available_additional_costs[ $additional_cost_setting['based_on'] ] ) ) {
/** @var AbstractAdditionalCost $additional_cost */
$additional_cost = $this->available_additional_costs[ $additional_cost_setting['based_on'] ];
$additional_cost->set_rule( $this );
$additional_costs += $additional_cost->calculate_cost_with_method_settings( $shipping_contents, $additional_cost_setting, $logger, $this->method_settings );
}
}
return $additional_costs;
}
/**
* @return array
*/
public function get_rules_settings(): array {
return $this->rule_settings;
}
/**
* @param int $rule_number .
*
* @return string
*/
public function format_for_log( $rule_number ) {
// Translators: rule number.
return sprintf( __( 'Rule %1$s:', 'flexible-shipping' ), $rule_number );
}
}

View file

@ -1,197 +0,0 @@
<?php
/**
* Class SettingsProcessor
*
* @package WPDesk\FS\TableRate\Rule\Settings
*/
namespace WPDesk\FS\TableRate\Rule\Settings;
use FSVendor\WPDesk\Forms\Field;
use WPDesk\Forms\Field\InputNumberField;
use WPDesk\FS\TableRate\Rule\Condition\Condition;
use WPDesk\FS\TableRate\Rule\Condition\ConditionsFactory;
use WPDesk\FS\TableRate\Rule\Cost\Additional;
use WPDesk\FS\TableRate\Rule\Cost\AdditionalCost;
use WPDesk\FS\TableRate\Rule\Cost\Cost;
use WPDesk\FS\TableRate\Rule\SpecialAction\SpecialAction;
/**
* Can process rules settings.
*/
class SettingsProcessor {
/**
* @var array
*/
private $posted_settings;
/**
* @var Condition[]
*/
private $conditions;
/**
* @var Field[]
*/
private $costs_fields;
/**
* @var Field[]
*/
private $additional_costs_fields;
/**
* @var Field[]
*/
private $special_action_fields;
/**
* SettingsProcessor constructor.
*
* @param array $posted_settings .
* @param Condition[] $conditions .
* @param Field[] $costs_fields .
* @param Field[] $additional_costs_fields .
* @param Field[] $special_action_fields .
*/
public function __construct(
array $posted_settings,
array $conditions,
array $costs_fields,
array $additional_costs_fields,
array $special_action_fields
) {
$this->posted_settings = $posted_settings;
$this->conditions = $conditions;
$this->costs_fields = $costs_fields;
$this->additional_costs_fields = $additional_costs_fields;
$this->special_action_fields = $special_action_fields;
}
/**
* @return array
*/
public function prepare_settings() {
$settings = [];
foreach ( $this->posted_settings as $rule_id => $rule_posted_settings ) {
$rule_settings = [
'conditions' => $this->prepare_conditions( $rule_posted_settings['conditions'] ?? [] ),
];
$rule_settings = $this->prepare_costs( $rule_settings, $rule_posted_settings );
$rule_settings = $this->prepare_costs_additional( $rule_settings, $rule_posted_settings );
$rule_settings = $this->prepare_special_action( $rule_settings, $rule_posted_settings );
$settings[] = $rule_settings;
}
return $settings;
}
/**
* @param array $rule_settings .
* @param array $rule_posted_settings .
*
* @return array
*/
private function prepare_costs( array $rule_settings, array $rule_posted_settings ) {
foreach ( $this->costs_fields as $field ) {
$rule_settings_value = isset( $rule_posted_settings[ $field->get_name() ] ) ? $rule_posted_settings[ $field->get_name() ] : '';
$rule_settings[ $field->get_name() ] = $this->sanitize_and_format_field( $rule_settings_value, $field );
}
return $rule_settings;
}
/**
* @param array $rule_settings .
* @param array $rule_posted_settings .
*
* @return array
*/
private function prepare_costs_additional( array $rule_settings, array $rule_posted_settings ) {
$rule_settings['additional_costs'] = [];
if ( isset( $rule_posted_settings['additional_costs'] ) && is_array( $rule_posted_settings['additional_costs'] ) ) {
foreach ( $rule_posted_settings['additional_costs'] as $posted_additional_cost ) {
$additional_cost = [];
foreach ( $this->additional_costs_fields as $field ) {
$additional_cost_value = isset( $posted_additional_cost[ $field->get_name() ] ) ? $posted_additional_cost[ $field->get_name() ] : '';
$additional_cost[ $field->get_name() ] = $this->sanitize_and_format_field( $additional_cost_value, $field );
}
$rule_settings['additional_costs'][] = $additional_cost;
}
}
return $rule_settings;
}
/**
* @param array $rule_settings .
* @param array $rule_posted_settings .
*
* @return array
*/
private function prepare_special_action( array $rule_settings, array $rule_posted_settings ) {
foreach ( $this->special_action_fields as $field ) {
$rule_settings[ $field->get_name() ] = isset( $rule_posted_settings[ $field->get_name() ] ) ? sanitize_text_field( $rule_posted_settings[ $field->get_name() ] ) : '';
}
return $rule_settings;
}
/**
* @param array $rule_conditions .
*
* @return array
*/
private function prepare_conditions( array $rule_conditions ) {
$conditions = [];
foreach ( $rule_conditions as $rule_condition ) {
$sanitized_condition = sanitize_key( $rule_condition['condition_id'] ?? [] );
$condition_normalized = [ 'condition_id' => $sanitized_condition ];
if ( isset( $this->conditions[ $sanitized_condition ] ) ) {
list( $rule_condition, $condition_normalized ) = $this->prepare_condition_fields( $sanitized_condition, $rule_condition, $condition_normalized );
$conditions[] = $condition_normalized;
}
}
return $conditions;
}
/**
* @param string $sanitized_condition .
* @param array $rule_condition .
* @param array $condition_normalized .
*
* @return array
*/
private function prepare_condition_fields( $sanitized_condition, $rule_condition, array $condition_normalized ) {
foreach ( $this->conditions[ $sanitized_condition ]->get_fields() as $field ) {
$rule_condition_value = isset( $rule_condition[ $field->get_name() ] ) ? $rule_condition[ $field->get_name() ] : '';
$condition_normalized[ $field->get_name() ] = $this->sanitize_and_format_field( $rule_condition_value, $field );
}
return [ $rule_condition, $condition_normalized ];
}
/**
* @param string|array $value .
* @param Field $field .
*/
private function sanitize_and_format_field( $value, $field ) {
if ( $field instanceof Field\InputNumberField ) {
return $this->format_number_field( sanitize_text_field( $value ) );
} else {
return $field->is_multiple() ? array_map( 'sanitize_text_field', is_array( $value ) ? $value : [] ) : sanitize_text_field( $value );
}
}
/**
* @param string $value .
*
* @return string
*/
private function format_number_field( $value ) {
return str_replace( ',', '.', $value );
}
}

View file

@ -1,136 +0,0 @@
<?php
/**
* Class DestinationAddress
*
* @package WPDesk\FS\TableRate\Rule\ShippingContents
*/
namespace WPDesk\FS\TableRate\Rule\ShippingContents;
/**
* Destination address.
*/
class DestinationAddress {
/**
* @var string
*/
private $country;
/**
* @var string
*/
private $state;
/**
* @var string
*/
private $postcode;
/**
* @var string
*/
private $city;
/**
* @var string
*/
private $address;
/**
* @var string
*/
private $address_1;
/**
* @var string
*/
private $address_2;
/**
* DestinationAddress constructor.
*
* @param string $country .
* @param string $state .
* @param string $postcode .
* @param string $city .
* @param string $address .
* @param string $address_1 .
* @param string $address_2 .
*/
public function __construct( $country, $state, $postcode, $city, $address, $address_1, $address_2 ) {
$this->country = $country;
$this->state = $state;
$this->postcode = $postcode;
$this->city = $city;
$this->address = $address;
$this->address_1 = $address_1;
$this->address_2 = $address_2;
}
/**
* @return string
*/
public function get_country() {
return $this->country;
}
/**
* @return string
*/
public function get_state() {
return $this->state;
}
/**
* @return string
*/
public function get_postcode() {
return $this->postcode;
}
/**
* @return string
*/
public function get_city() {
return $this->city;
}
/**
* @return string
*/
public function get_address() {
return $this->address;
}
/**
* @return string
*/
public function get_address_1() {
return $this->address_1;
}
/**
* @return string
*/
public function get_address_2() {
return $this->address_2;
}
/**
* @return string
*/
public function prepare_data_for_log() {
return sprintf(
'country: %1$s, state: %2$s, postcode: %3$s, city: %4$s, address: %5$s, address_1: %6$s, address_2: %7$s',
$this->country,
$this->state,
$this->postcode,
$this->city,
$this->address,
$this->address_1,
$this->address_2
);
}
}

View file

@ -1,32 +0,0 @@
<?php
/**
* Class DestinationAddressFactory
*
* @package WPDesk\FS\TableRate\Rule\ShippingContents
*/
namespace WPDesk\FS\TableRate\Rule\ShippingContents;
/**
* Can create destination address.
*/
class DestinationAddressFactory {
/**
* @param array $destination .
*
* @return DestinationAddress
*/
public static function create_from_package_destination( array $destination ) {
return new DestinationAddress(
isset( $destination['country'] ) ? $destination['country'] : '',
isset( $destination['state'] ) ? $destination['state'] : '',
isset( $destination['postcode'] ) ? $destination['postcode'] : '',
isset( $destination['city'] ) ? $destination['city'] : '',
isset( $destination['address'] ) ? $destination['address'] : '',
isset( $destination['address_1'] ) ? $destination['address_1'] : '',
isset( $destination['address_2'] ) ? $destination['address_2'] : ''
);
}
}

View file

@ -1,80 +0,0 @@
<?php
/**
* Interface ShippingContents
*
* @package WPDesk\FS\TableRate
*/
namespace WPDesk\FS\TableRate\Rule\ShippingContents;
use WPDesk\FS\TableRate\Rule\ContentsFilter;
/**
* Can provide shipping contents.
*/
interface ShippingContents {
/**
* @param int $weight_rounding_precision .
*/
public function set_weight_rounding_precision( $weight_rounding_precision );
/**
* @return array
*/
public function get_contents();
/**
* @return float
*/
public function get_contents_cost();
/**
* @param bool $round .
*
* @return float
*/
public function get_contents_weight( $round = true );
/**
* @return int
*/
public function get_contents_items_count();
/**
* @param ContentsFilter $contents_filter .
*/
public function filter_contents( ContentsFilter $contents_filter );
/**
* Returns non filtered contents.
*
* @return array
*/
public function get_non_filtered_contents();
/**
* Reset contents to non filtered.
*
* @return array
*/
public function reset_contents();
/**
* @return DestinationAddress
*/
public function get_destination_address();
/**
* @return string
*/
public function get_currency();
public function set_meta( ShippingContentsMeta $meta );
public function get_meta( string $key ): ?ShippingContentsMeta;
public function get_calculated_shipping_cost(): float;
public function set_calculated_shipping_cost( float $calculated_shipping_cost ): void;
}

View file

@ -1,276 +0,0 @@
<?php
/**
* Class ShippingContentsImplementation
*
* @package WPDesk\FS\TableRate
*/
namespace WPDesk\FS\TableRate\Rule\ShippingContents;
use WPDesk\FS\TableRate\Rule\ContentsFilter;
/**
* Can provide shipping contents.
*/
class ShippingContentsImplementation implements ShippingContents {
/**
* @var array
*/
private $non_filtered_contents;
/**
* @var array
*/
private $contents;
/**
* @var bool
*/
private $prices_includes_tax;
/**
* @var float
*/
private $contents_cost;
/**
* @var float
*/
private $contents_weight;
/**
* @var int
*/
private $cost_rounding_precision;
/**
* @var DestinationAddress
*/
private $destination_address;
/**
* @var string
*/
private $currency;
/**
* @var int
*/
private $weight_rounding_precision = 6;
/**
* @var ShippingContentsMeta[]
*/
private $meta = [];
private float $calculated_shipping_cost = 0.0;
/**
* ShippingContents constructor.
*
* @param array $contents .
* @param bool $prices_includes_tax .
* @param int $cost_rounding_precision .
* @param DestinationAddress $destination_address .
* @param string $currency .
*/
public function __construct( $contents, $prices_includes_tax, $cost_rounding_precision, $destination_address, $currency ) {
$this->contents = $contents;
$this->non_filtered_contents = $contents;
$this->prices_includes_tax = $prices_includes_tax;
$this->cost_rounding_precision = $cost_rounding_precision;
$this->destination_address = $destination_address;
$this->currency = $currency;
}
/**
* @param int $weight_rounding_precision .
*/
public function set_weight_rounding_precision( $weight_rounding_precision ) {
$this->weight_rounding_precision = $weight_rounding_precision;
}
/**
* @return array
*/
public function get_contents() {
return $this->contents;
}
/**
* @return float
*/
public function get_contents_cost() {
if ( ! isset( $this->contents_cost ) ) {
$this->contents_cost = $this->calculate_contents_cost();
}
return round( $this->contents_cost, $this->cost_rounding_precision );
}
/**
* @param bool $round .
*
* @return float
*/
public function get_contents_weight( $round = true ) {
if ( ! isset( $this->contents_weight ) ) {
$this->contents_weight = $this->calculate_contents_weight();
}
if ( $round ) {
return round( $this->contents_weight, $this->weight_rounding_precision );
}
return $this->contents_weight;
}
/**
* @return float
*/
private function calculate_contents_weight() {
$weight = 0.0;
foreach ( $this->contents as $item ) {
$weight += $this->get_item_weight( $item );
}
return $weight;
}
/**
* @param array $item .
*
* @return float
*/
private function get_item_weight( $item ) {
return (float) $item['data']->get_weight() * (float) $item['quantity'];
}
/**
* @return float
*/
private function calculate_contents_cost() {
$cost = 0.0;
foreach ( $this->contents as $item ) {
$cost += $this->get_item_cost( $item );
}
return $cost;
}
/**
* @param array $item .
*
* @return float
*/
private function get_item_cost( $item ) {
$line_total = 0.0;
if ( $this->prices_includes_tax ) {
if ( isset( $item['line_total'] ) ) {
$line_total = (float) $item['line_total'];
}
if ( isset( $item['line_tax'] ) ) {
$line_total += (float) $item['line_tax'];
}
} elseif ( isset( $item['line_total'] ) ) {
$line_total = (float) $item['line_total'];
}
return $line_total;
}
/**
* @return int
*/
public function get_contents_items_count() {
$items_count = 0;
foreach ( $this->contents as $item ) {
$items_count += $item['quantity'];
}
return $items_count;
}
/**
* @param ContentsFilter $contents_filter .
*/
public function filter_contents( ContentsFilter $contents_filter ) {
$this->contents = $contents_filter->get_filtered_contents( $this->contents );
$this->contents_cost = null;
$this->contents_weight = null;
do_action( 'flexible-shipping/shipping-contents/filter/after', $this );
}
/**
* Returns non filtered contents.
*
* @return array
*/
public function get_non_filtered_contents() {
return $this->non_filtered_contents;
}
/**
* Reset contents to non filtered.
*
* @return void
*/
public function reset_contents() {
$this->contents = $this->non_filtered_contents;
$this->contents_cost = null;
$this->contents_weight = null;
do_action( 'flexible-shipping/shipping-contents/reset/after', $this );
}
/**
* @return DestinationAddress
*/
public function get_destination_address() {
return $this->destination_address;
}
/**
* @return string
*/
public function get_currency() {
return $this->currency;
}
/**
* @param ShippingContentsMeta $meta .
*
* @return $this
*/
public function set_meta( ShippingContentsMeta $meta ): ShippingContentsImplementation {
$this->meta[ $meta->get_key() ] = $meta;
return $this;
}
/**
* @param string $key
*
* @return ShippingContentsMeta|null
*/
public function get_meta( string $key ): ?ShippingContentsMeta {
return $this->meta[ $key ] ?? null;
}
/**
* @return float
*/
public function get_calculated_shipping_cost(): float {
return $this->calculated_shipping_cost;
}
/**
* @param float $calculated_shipping_cost
*/
public function set_calculated_shipping_cost( float $calculated_shipping_cost ): void {
$this->calculated_shipping_cost = $calculated_shipping_cost;
}
}

View file

@ -1,45 +0,0 @@
<?php
/**
* Class ShippingContentsMeta
*/
namespace WPDesk\FS\TableRate\Rule\ShippingContents;
/**
* Shipping Contents Meta.
*/
class ShippingContentsMeta {
/**
* @var string
*/
private $key;
/**
* @var mixed
*/
private $value;
/**
* @param string $key .
* @param mixed $value .
*/
public function __construct( string $key, $value ) {
$this->key = $key;
$this->value = $value;
}
/**
* @return string
*/
public function get_key(): string {
return $this->key;
}
/**
* @return mixed
*/
public function get_value() {
return $this->value;
}
}

View file

@ -1,74 +0,0 @@
<?php
/**
* Class AbstractSpecialAction
*
* @package WPDesk\FS\TableRate\Rule\SpecialAction
*/
namespace WPDesk\FS\TableRate\Rule\SpecialAction;
/**
* Abstract special action.
*/
abstract class AbstractSpecialAction implements SpecialAction {
/**
* @var string
*/
private $special_action_id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $description;
/**
* AbstractSpecialAction constructor.
*
* @param string $special_action_id .
* @param string $name .
* @param string $description .
*/
public function __construct( $special_action_id, $name, $description = '' ) {
$this->special_action_id = $special_action_id;
$this->name = $name;
$this->description = $description;
}
/**
* @return string
*/
public function get_special_action_id() {
return $this->special_action_id;
}
/**
* @return string
*/
public function get_name() {
return $this->name;
}
/**
* @return string
*/
public function get_description() {
return $this->description;
}
/**
* @return bool
*/
abstract public function is_cancel();
/**
* @return bool
*/
abstract public function is_stop();
}

View file

@ -1,35 +0,0 @@
<?php
/**
* Class None
*
* @package WPDesk\FS\TableRate\Rule\SpecialAction
*/
namespace WPDesk\FS\TableRate\Rule\SpecialAction;
/**
* None special action.
*/
class None extends AbstractSpecialAction {
/**
* None constructor.
*/
public function __construct() {
parent::__construct( 'none', __( 'None', 'flexible-shipping' ) );
}
/**
* @inheritDoc
*/
public function is_cancel() {
return false;
}
/**
* @inheritDoc
*/
public function is_stop() {
return false;
}
}

View file

@ -1,40 +0,0 @@
<?php
/**
* Interface SpecialAction
*
* @package WPDesk\FS\TableRate\Rule\SpecialAction
*/
namespace WPDesk\FS\TableRate\Rule\SpecialAction;
/**
* Special action interface.
*/
interface SpecialAction {
/**
* @return string
*/
public function get_special_action_id();
/**
* @return string
*/
public function get_name();
/**
* @return string
*/
public function get_description();
/**
* @return bool
*/
public function is_cancel();
/**
* @return bool
*/
public function is_stop();
}

View file

@ -62,7 +62,7 @@ class SpecialActionFieldsFactory implements FieldProvider {
->set_options( $this->get_special_action_options() )
->add_class( 'hs-beacon-search' )
->add_class( 'special-action' )
->add_data( 'beacon_search', __( 'special action', 'flexible-shipping' ) ),
->add_data( 'beacon_search', __( 'special action', 'flexible-shipping-rules' ) ),
);
}

View file

@ -1,54 +0,0 @@
<?php
namespace WPDesk\FS\TableRate;
/**
* Class RulesSettingsFactory
*
* @package WPDesk\FS\TableRate
*/
class RulesSettingsFactory {
/**
* @var SingleRuleSettings[]
*/
private $rules = array();
/**
* @param $settings_array
*
* @return RulesSettingsFactory
*/
public static function create_from_array( $settings_array ) {
$rules_settings = new self();
if ( ! is_array( $settings_array ) ) {
return $rules_settings;
}
foreach ( $settings_array as $single_rule_settings_row ) {
$rules_settings->add_single_rule_settings( new SingleRuleSettings( $single_rule_settings_row ) );
}
return $rules_settings;
}
/**
* @return array
*/
public function get_normalized_settings() {
$normalized_settings = [];
foreach ( $this->rules as $rule ) {
$normalized_settings[] = $rule->get_normalized_settings();
}
return $normalized_settings;
}
/**
* @param SingleRuleSettings $single_rule_settings
*/
private function add_single_rule_settings( SingleRuleSettings $single_rule_settings ) {
$this->rules[] = $single_rule_settings;
}
}

View file

@ -52,6 +52,11 @@ class RulesSettingsField {
*/
private $value;
/**
* @var array
*/
private $shipping_method_settings;
/**
* RulesSettings constructor.
*
@ -60,13 +65,15 @@ class RulesSettingsField {
* @param string $settings_field_title .
* @param array $settings .
* @param array $value .
* @param array $shipping_method_settings .
*/
public function __construct( $settings_field_id, $settings_field_name, $settings_field_title, $settings, $value = null ) {
public function __construct( $settings_field_id, $settings_field_name, $settings_field_title, $settings, $value = null, $shipping_method_settings = [] ) {
$this->settings_field_id = $settings_field_id;
$this->settings_field_name = $settings_field_name;
$this->settings_field_title = $settings_field_title;
$this->settings = $settings;
$this->value = $value;
$this->shipping_method_settings = $shipping_method_settings;
}
/**
@ -91,7 +98,7 @@ class RulesSettingsField {
$available_conditions = array_values( $available_conditions );
$translations = $this->get_translations();
$pro_features_data = $this->get_pro_features_data();
$rules_table_settings = $this->get_table_settings();
$table_settings = $this->get_table_settings();
$cost_settings_fields = $this->get_available_cost_settings();
$additional_cost_fields = $this->get_additional_cost_fields();
@ -100,6 +107,24 @@ class RulesSettingsField {
$is_pro_activated = defined( 'FLEXIBLE_SHIPPING_PRO_VERSION' );
$rules_table_settings = [
'rules_settings' => $rules_settings,
'table_settings' => $table_settings,
'translations' => $translations,
'available_conditions' => $available_conditions,
'cost_settings_fields' => $cost_settings_fields,
'special_action_fields' => $special_action_fields,
'additional_cost_fields' => $additional_cost_fields,
'preconfigured_scenarios' => $preconfigured_scenarios,
'is_pro_activated' => $is_pro_activated,
'pro_features_data' => $pro_features_data,
'paste_available' => true,
'ai_button_available' => true,
'ai_button_url' => 'https://octol.io/fs-rules-table-ai',
];
$rules_table_settings = apply_filters( 'flexible-shipping/rules-table/settings', $rules_table_settings, $this->shipping_method_settings );
include __DIR__ . '/views/shipping-method-settings-rules.php';
return ob_get_clean();

View file

@ -39,7 +39,24 @@ class MethodDescription implements Hookable {
* Hooks.
*/
public function hooks() {
add_action( 'woocommerce_after_shipping_rate', array( $this, 'display_description_if_present' ), 10, 2 );
add_action( 'woocommerce_after_shipping_rate', [ $this, 'display_description_if_present' ], 10, 2 );
add_filter( 'woocommerce_package_rates', [ $this, 'add_description_to_rate_if_present' ] );
}
/**
* @param WC_Shipping_Rate[] $rates .
*
* @return WC_Shipping_Rate[]
*/
public function add_description_to_rate_if_present( $rates ) {
foreach ( $rates as $rate ) {
if ( ! $rate instanceof WC_Shipping_Rate || ! $this->should_display_method_description( $rate ) ) {
continue;
}
$rate->description = $this->get_method_description( $rate );
}
return $rates;
}
/**

View file

@ -10,8 +10,8 @@ namespace WPDesk\FS\TableRate\ShippingMethod;
use FSVendor\WPDesk\Forms\Field;
use FSVendor\WPDesk\FS\TableRate\Settings\CartCalculationOptions;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettingsImplementation;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use FSVendor\Psr\Log\LoggerInterface;
use FSVendor\Psr\Log\NullLogger;
use WC_Cart;
use WC_Shipping_Method;
use WPDesk\FS\TableRate\Rule\Condition\Condition;

View file

@ -7,10 +7,10 @@
namespace WPDesk\FS\TableRate;
use FSVendor\Psr\Log\LoggerInterface;
use FSVendor\WPDesk\FS\TableRate\Logger\NoticeLogger;
use FSVendor\WPDesk\FS\TableRate\Logger\ShippingMethodLogger;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettingsFactory;
use Psr\Log\LoggerInterface;
use WC_Shipping_Method;
use WPDesk\FS\TableRate\Rule\Condition\ConditionsFactory;
use WPDesk\FS\TableRate\Rule\Cost\RuleAdditionalCostFactory;
@ -185,7 +185,14 @@ class ShippingMethodSingle extends WC_Shipping_Method {
public function generate_shipping_rules_html( $key, $data ) {
$field_key = $this->get_field_key( $key );
$method_rules_settings = $this->get_option( $key, '[]' );
$rules_settings = new RulesSettingsField( $field_key, $field_key, $data['title'], $data, ! is_array( $method_rules_settings ) ? json_decode( $method_rules_settings, true ) : $method_rules_settings );
$rules_settings = new RulesSettingsField(
$field_key,
$field_key,
$data['title'],
$data,
! is_array( $method_rules_settings ) ? json_decode( $method_rules_settings, true ) : $method_rules_settings,
$this->instance_settings
);
return $rules_settings->render();
}

View file

@ -28,12 +28,19 @@ class SettingsFields implements Hookable {
* @return bool
*/
public function remove_modal_settings_from_shipping_methods( $supports, $feature, $shipping_method ) {
if ( isset( $_GET['page'] ) && $_GET['page'] === 'wc-settings'
&& isset( $_GET['tab'] ) && $_GET['tab'] === 'shipping'
&& isset( $_GET['instance_id'] )
) {
if ( $feature === 'instance-settings-modal' ) {
return false;
}
}
if ( in_array( $shipping_method->id ?? '', $this->get_allowed_shipping_methods_instance_settings(), true ) ) {
if ( $feature === 'instance-settings-modal' ) {
return false;
}
}
return $supports;
}
@ -93,13 +100,14 @@ class SettingsFields implements Hookable {
*/
public function generate_shipping_rules_html( $field_html, $key, $data, $shipping_method ): string {
$title = $data['title'];
$field_key = 'woocommerce_' . $shipping_method->id . '_' . self::SETTING_METHOD_RULES;
$field_key = $shipping_method->plugin_id . $shipping_method->id . '_' . self::SETTING_METHOD_RULES;
$rules_settings = new RulesSettingsField(
$field_key,
$field_key,
$title,
[],
json_decode( $shipping_method->get_option( self::SETTING_METHOD_RULES, json_encode( ( new DefaultRulesSettings() )->get_normalized_settings() ) ), true )
json_decode( $shipping_method->get_option( self::SETTING_METHOD_RULES, json_encode( ( new DefaultRulesSettings() )->get_normalized_settings() ) ), true ),
$shipping_method->instance_settings
);
return $rules_settings->render();
@ -143,8 +151,10 @@ class SettingsFields implements Hookable {
* @return string
*/
public static function sanitize_shipping_rules( $value ) {
if ( is_array( $value ) ) {
return json_encode( $value );
} else {
return $value;
}
}
}

Some files were not shown because too many files have changed in this diff Show more