Skip to content

Commit

Permalink
Updates to 4.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Woo committed Jun 4, 2024
1 parent a079134 commit 0e20c86
Show file tree
Hide file tree
Showing 9 changed files with 593 additions and 160 deletions.
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
*** Woo Min/Max Quantities Changelog ***

2024.06.04 - version 4.3.2
* Tweak - Updated REST API validation to prevent incompatible quantity rules from being set.
* Fix - Hide express checkout buttons on Single product page when Min/Max quantity can't be verified.
* Fix - Resolved a fatal error triggered when trying to get the 'Group of' value of orphaned variations via REST API.
* Fix - Improved validation of values when getting maintenance and dismissed notices from the DB.

2024.05.15 - version 4.3.1
* Fix - Resolved an issue in the REST API that returned a cached 'Group of' value.
* Fix - Resolved a fatal error triggered by the REST API when trying to set a 'Group of' value with an empty Min/Max Quantity.
Expand Down
6 changes: 3 additions & 3 deletions includes/admin/class-wc-min-max-quantities-admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Admin notices handling.
*
* @class WC_Min_Max_Quantities_Admin_Notices
* @version 4.2.3
* @version 4.3.2
*/
class WC_Min_Max_Quantities_Admin_Notices {

Expand Down Expand Up @@ -61,9 +61,9 @@ public static function init() {
$GLOBALS[ 'sw_store' ][ 'notices_unique' ] = array();
}

self::$maintenance_notices = get_option( 'wc_mmq_maintenance_notices', array() );
self::$maintenance_notices = is_array( get_option( 'wc_mmq_maintenance_notices' ) ) ? get_option( 'wc_mmq_maintenance_notices' ) : array();
self::$dismissed_notices = get_user_meta( get_current_user_id(), 'wc_mmq_dismissed_notices', true );
self::$dismissed_notices = empty( self::$dismissed_notices ) ? array() : self::$dismissed_notices;
self::$dismissed_notices = is_array( self::$dismissed_notices ) ? self::$dismissed_notices : array();

// Show meta box notices.
add_action( 'admin_notices', array( __CLASS__, 'output_notices' ) );
Expand Down
323 changes: 204 additions & 119 deletions includes/api/class-wc-mmq-rest-api.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* @package Woo Min/Max Quantities
* @since 4.0.4
* @version 4.3.2
*/

// Exit if accessed directly.
Expand Down Expand Up @@ -81,8 +82,9 @@ protected function __construct() {

// Define dependencies.
$this->required = array(
'pao' => '3.0.14',
'blocks' => '7.2.0'
'pao' => '3.0.14',
'blocks' => '7.2.0',
'wc_stripe' => '4.1.0' // when wc_stripe_hide_payment_request_on_product_page filter was made usable.
);

// Initialize.
Expand Down Expand Up @@ -123,6 +125,8 @@ public function is_module_loaded( $name ) {

/**
* Load compatibility classes.
*
* @version 4.3.2
*
* @return void
*/
Expand All @@ -140,6 +144,21 @@ public function module_includes() {
$module_paths[ 'product_addons' ] = WC_MMQ_ABSPATH . 'includes/compatibility/modules/class-wc-min-max-quantities-addons.php';
}

// Smart button on Product page: PayPal compatibility.
if ( class_exists( '\WooCommerce\PayPalCommerce\PluginModule' ) ) {
$module_paths[ 'paypal' ] = WC_MMQ_ABSPATH . '/includes/compatibility/modules/class-wc-min-max-quantities-paypal-compatibility.php';
}

// Express checkout on Product page: Stripe compatibility.
if ( class_exists( 'WC_Stripe' ) && defined( 'WC_STRIPE_VERSION' ) && version_compare( WC_STRIPE_VERSION, $this->required[ 'wc_stripe' ] ) >= 0 ) {
$module_paths[ 'wc_stripe' ] = WC_MMQ_ABSPATH . '/includes/compatibility/modules/class-wc-min-max-quantities-stripe-compatibility.php';
}

// Express checkout on Product page: WooPayments compatibility.
if ( class_exists( 'WC_Payments' ) ) {
$module_paths[ 'wcpay' ] = WC_MMQ_ABSPATH . '/includes/compatibility/modules/class-wc-min-max-quantities-wc-payments-compatibility.php';
}

/**
* 'woocommerce_mmq_compatibility_modules' filter.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* WC_Min_Max_Quantities_PayPal_Compatibility class
*
* @package Woo Min Max Quantities
* @since 4.3.2
*/

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

/**
* PayPal Compatibility.
*
* @version 4.3.2
*/
class WC_Min_Max_Quantities_PayPal_Compatibility {

// Hide smart buttons in product pages when Min or Max qty/value are set.
public static function init() {
add_filter( 'woocommerce_paypal_payments_product_supports_payment_request_button', array( __CLASS__, 'handle_smart_buttons' ), 10, 2 );
}

/**
* Hide smart buttons in product pages when Min or Max qty/value are set.
*
* @param bool $is_supported
* @param WC_Product $product
*
* @return bool
*/
public static function handle_smart_buttons( $is_supported, $product ) {
// If the smart button is not supported by some other plugin, respect that.
if ( ! $is_supported ) {
return $is_supported;
}

$mmq_instance = WC_Min_Max_Quantities::get_instance();
return $mmq_instance->can_display_express_checkout( $product );
}
}

WC_Min_Max_Quantities_PayPal_Compatibility::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* WC_Min_Max_Quantities_Stripe_Compatibility class
*
* @package Woo Min Max Quantities
* @since 4.3.2
*/

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

/**
* Stripe Compatibility.
*
* @version 4.3.2
*/
class WC_Min_Max_Quantities_Stripe_Compatibility {

// Hide smart buttons in product pages when Min or Max qty/value are set.
public static function init() {
add_filter( 'wc_stripe_hide_payment_request_on_product_page', array( __CLASS__, 'handle_express_checkout_buttons' ), 10, 2 );
}

/**
* Hide express checkout buttons in product pages when Min or Max qty/value are set.
*
* @param bool $hide
* @param WP_Post $post
*
* @return bool
*/
public static function handle_express_checkout_buttons( $hide, $post = null ) {
// If the button is already hidden by some other plugin, respect that.
if ( $hide ) {
return $hide;
}

if ( is_null( $post ) ) {
global $post;
}

if ( ! is_object( $post ) || empty( $post->ID ) ) {
return $hide;
}

$product = wc_get_product( $post->ID );
if ( $product && is_a( $product, 'WC_Product' ) ) {
$mmq_instance = WC_Min_Max_Quantities::get_instance();
$hide = ! $mmq_instance->can_display_express_checkout( $product ); // the filter needs true for hiding the button.
return $hide;
}

return $hide;
}
}

WC_Min_Max_Quantities_Stripe_Compatibility::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* WC_Min_Max_Quantities_WC_Payments_Compatibility class
*
* @package Woo Min Max Quantities
* @since 4.3.2
*/

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

/**
* WC_Payments Compatibility.
*
* @version 4.3.2
*/
class WC_Min_Max_Quantities_WC_Payments_Compatibility {

public static function init() {
// Hide express checkout buttons in product pages when Min or Max qty/value are set.
add_filter( 'wcpay_payment_request_is_product_supported', array( __CLASS__, 'handle_express_checkout_buttons' ), 10, 2 );
add_filter( 'wcpay_woopay_button_is_product_supported', array( __CLASS__, 'handle_express_checkout_buttons' ), 10, 2 );
}

/**
* Hide express checkout buttons in product pages when Min or Max qty/value are set.
*
* @param bool $is_supported
* @param WC_Product $product
*
* @return bool
*/
public static function handle_express_checkout_buttons( $is_supported, $product ) {
// If the smart button is not supported by some other plugin, respect that.
if ( ! $is_supported ) {
return $is_supported;
}

$mmq_instance = WC_Min_Max_Quantities::get_instance();
return $mmq_instance->can_display_express_checkout( $product );
}
}

WC_Min_Max_Quantities_WC_Payments_Compatibility::init();
63 changes: 29 additions & 34 deletions languages/woocommerce-min-max-quantities.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the GNU General Public License v3.0.
msgid ""
msgstr ""
"Project-Id-Version: Woo Min/Max Quantities 4.3.1\n"
"Project-Id-Version: Woo Min/Max Quantities 4.3.2\n"
"Report-Msgid-Bugs-To: https://woocommerce.com/my-account/create-a-ticket/\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-05-15T12:22:54+00:00\n"
"POT-Creation-Date: 2024-06-04T09:20:25+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.10.0\n"
"language-team: LANGUAGE <EMAIL@ADDRESS>\n"
Expand Down Expand Up @@ -244,82 +244,77 @@ msgstr ""
msgid "Support"
msgstr ""

#. translators: Group of quantity
#: includes/api/class-wc-mmq-rest-api.php:143
#: includes/api/class-wc-mmq-rest-api.php:389
msgid "The minimum quantity must be a multiple of %d."
#: includes/api/class-wc-mmq-rest-api.php:159
#: includes/api/class-wc-mmq-rest-api.php:483
msgid "The Allow Combinations option can only be set for Variable Products."
msgstr ""

#. translators: Minimum quantity
#: includes/api/class-wc-mmq-rest-api.php:160
#: includes/api/class-wc-mmq-rest-api.php:405
msgid "The maximum quantity must be greater than %d, which is the Minimum Quantity."
#: includes/api/class-wc-mmq-rest-api.php:186
#: includes/api/class-wc-mmq-rest-api.php:510
msgid "The minimum quantity must be less than %d, which is the Maximum Quantity."
msgstr ""

#. translators: Group of quantity
#: includes/api/class-wc-mmq-rest-api.php:165
#: includes/api/class-wc-mmq-rest-api.php:410
msgid "The maximum quantity must be a multiple of %d."
#: includes/api/class-wc-mmq-rest-api.php:191
#: includes/api/class-wc-mmq-rest-api.php:515
msgid "The minimum quantity must be a multiple of %d."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:184
#: includes/api/class-wc-mmq-rest-api.php:432
msgid "The Allow Combinations option can only be set for Variable Products."
#. translators: Group of quantity
#: includes/api/class-wc-mmq-rest-api.php:196
#: includes/api/class-wc-mmq-rest-api.php:520
msgid "The maximum quantity must be a multiple of %d."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:199
#: includes/api/class-wc-mmq-rest-api.php:253
msgid "Enable this option to set quantity rules for a specific variation."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:205
#: includes/api/class-wc-mmq-rest-api.php:259
msgid "Require variations to be purchased in multiples of this value."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:210
#: includes/api/class-wc-mmq-rest-api.php:264
msgid "Minimum required variation quantity."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:215
#: includes/api/class-wc-mmq-rest-api.php:269
msgid "Maximum allowed variation quantity."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:220
#: includes/api/class-wc-mmq-rest-api.php:274
msgid "Exclude variation from order quantity and value rules."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:226
#: includes/api/class-wc-mmq-rest-api.php:280
msgid "Exclude variation from category quantity rules."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:271
#: includes/api/class-wc-mmq-rest-api.php:322
msgid "Require products to be purchased in multiples of this value."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:276
#: includes/api/class-wc-mmq-rest-api.php:327
msgid "Minimum required product quantity."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:281
#: includes/api/class-wc-mmq-rest-api.php:332
msgid "Maximum allowed product quantity."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:286
#: includes/api/class-wc-mmq-rest-api.php:337
msgid "Exclude product from order quantity and value rules."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:292
#: includes/api/class-wc-mmq-rest-api.php:343
msgid "Exclude product from category quantity rules."
msgstr ""

#: includes/api/class-wc-mmq-rest-api.php:298
#: includes/api/class-wc-mmq-rest-api.php:349
msgid "Enable this option to combine the quantities of all purchased variations when checking quantity rules."
msgstr ""

#. translators: Minimum quantity
#: includes/api/class-wc-mmq-rest-api.php:384
msgid "The minimum quantity must be less than %d, which is the Maximum Quantity."
msgstr ""

#: includes/class-wc-min-max-quantities-blocks.php:59
#: includes/class-wc-min-max-quantities-blocks.php:138
msgid "Sell in groups of"
Expand Down Expand Up @@ -365,8 +360,8 @@ msgstr ""
msgid "Enter a maximum quantity customers can buy in a single order. This is particularly useful for items that have limited quantity, like art or handmade goods."
msgstr ""

#: includes/compatibility/class-wc-min-max-quantities-compatibility.php:65
#: includes/compatibility/class-wc-min-max-quantities-compatibility.php:74
#: includes/compatibility/class-wc-min-max-quantities-compatibility.php:66
#: includes/compatibility/class-wc-min-max-quantities-compatibility.php:75
msgid "Foul!"
msgstr ""

Expand Down
Loading

0 comments on commit 0e20c86

Please sign in to comment.