Version Description
- Updated to work with the WooCommerce 2.6 cart ajax script.
Download this release
Release Info
| Developer | mikejolley |
| Plugin | |
| Version | 1.1.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.0 to 1.1.0
- assets/css/.sass-cache/6204c37d5a1b3dd02c2bcaccc507b6890dad22fe/wc-quantity-increment.scssc +0 -0
- assets/js/wc-quantity-increment.js +25 -14
- assets/js/wc-quantity-increment.min.js +1 -1
- includes/class-wc-quantity-increment.php +0 -29
- languages/WooCommerce-Quantity-Increment.pot +44 -0
- languages/woocommerce-quantity-increment-en_GB.mo +0 -0
- languages/woocommerce-quantity-increment-en_GB.po +0 -25
- readme.txt +14 -16
- woocommerce-quantity-increment.php +93 -101
- wordpress_org_assets/banner-1544x500.png +0 -0
- wordpress_org_assets/banner-772x250.png +0 -0
- wordpress_org_assets/icon-128x128.png +0 -0
- wordpress_org_assets/icon-256x256.png +0 -0
- wordpress_org_assets/wcqi.sketch +0 -0
assets/css/.sass-cache/6204c37d5a1b3dd02c2bcaccc507b6890dad22fe/wc-quantity-increment.scssc
DELETED
|
Binary file
|
assets/js/wc-quantity-increment.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
| 1 |
jQuery( function( $ ) {
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
// Get values
|
| 9 |
-
var $qty = $( this ).closest( '.quantity' ).find( '.qty'
|
| 10 |
currentVal = parseFloat( $qty.val() ),
|
| 11 |
max = parseFloat( $qty.attr( 'max' ) ),
|
| 12 |
min = parseFloat( $qty.attr( 'min' ) ),
|
|
@@ -20,26 +35,22 @@ jQuery( function( $ ) {
|
|
| 20 |
|
| 21 |
// Change the value
|
| 22 |
if ( $( this ).is( '.plus' ) ) {
|
| 23 |
-
|
| 24 |
-
if ( max && ( max == currentVal || currentVal > max ) ) {
|
| 25 |
$qty.val( max );
|
| 26 |
} else {
|
| 27 |
-
$qty.val( currentVal + parseFloat( step ) );
|
| 28 |
}
|
| 29 |
-
|
| 30 |
} else {
|
| 31 |
-
|
| 32 |
-
if ( min && ( min == currentVal || currentVal < min ) ) {
|
| 33 |
$qty.val( min );
|
| 34 |
} else if ( currentVal > 0 ) {
|
| 35 |
-
$qty.val( currentVal - parseFloat( step ) );
|
| 36 |
}
|
| 37 |
-
|
| 38 |
}
|
| 39 |
|
| 40 |
// Trigger change event
|
| 41 |
$qty.trigger( 'change' );
|
| 42 |
-
|
| 43 |
});
|
| 44 |
|
| 45 |
-
|
|
|
| 1 |
jQuery( function( $ ) {
|
| 2 |
|
| 3 |
+
if ( ! String.prototype.getDecimals ) {
|
| 4 |
+
String.prototype.getDecimals = function() {
|
| 5 |
+
var num = this,
|
| 6 |
+
match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
|
| 7 |
+
if ( ! match ) {
|
| 8 |
+
return 0;
|
| 9 |
+
}
|
| 10 |
+
return Math.max( 0, ( match[1] ? match[1].length : 0 ) - ( match[2] ? +match[2] : 0 ) );
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
|
| 14 |
+
function wcqi_refresh_quantity_increments(){
|
| 15 |
+
$( 'div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)' ).addClass( 'buttons_added' ).append( '<input type="button" value="+" class="plus" />' ).prepend( '<input type="button" value="-" class="minus" />' );
|
| 16 |
+
}
|
| 17 |
|
| 18 |
+
$( document ).on( 'updated_wc_div', function() {
|
| 19 |
+
wcqi_refresh_quantity_increments();
|
| 20 |
+
} );
|
| 21 |
+
|
| 22 |
+
$( document ).on( 'click', '.plus, .minus', function() {
|
| 23 |
// Get values
|
| 24 |
+
var $qty = $( this ).closest( '.quantity' ).find( '.qty'),
|
| 25 |
currentVal = parseFloat( $qty.val() ),
|
| 26 |
max = parseFloat( $qty.attr( 'max' ) ),
|
| 27 |
min = parseFloat( $qty.attr( 'min' ) ),
|
| 35 |
|
| 36 |
// Change the value
|
| 37 |
if ( $( this ).is( '.plus' ) ) {
|
| 38 |
+
if ( max && ( currentVal >= max ) ) {
|
|
|
|
| 39 |
$qty.val( max );
|
| 40 |
} else {
|
| 41 |
+
$qty.val( ( currentVal + parseFloat( step )).toFixed( step.getDecimals() ) );
|
| 42 |
}
|
|
|
|
| 43 |
} else {
|
| 44 |
+
if ( min && ( currentVal <= min ) ) {
|
|
|
|
| 45 |
$qty.val( min );
|
| 46 |
} else if ( currentVal > 0 ) {
|
| 47 |
+
$qty.val( ( currentVal - parseFloat( step )).toFixed( step.getDecimals() ) );
|
| 48 |
}
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
// Trigger change event
|
| 52 |
$qty.trigger( 'change' );
|
|
|
|
| 53 |
});
|
| 54 |
|
| 55 |
+
wcqi_refresh_quantity_increments();
|
| 56 |
+
});
|
assets/js/wc-quantity-increment.min.js
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
jQuery(function(
|
| 1 |
+
jQuery(function(a){function b(){a("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" class="plus" />').prepend('<input type="button" value="-" class="minus" />')}String.prototype.getDecimals||(String.prototype.getDecimals=function(){var a=this,b=(""+a).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return b?Math.max(0,(b[1]?b[1].length:0)-(b[2]?+b[2]:0)):0}),a(document).on("updated_wc_div",function(){b()}),a(document).on("click",".plus, .minus",function(){var b=a(this).closest(".quantity").find(".qty"),c=parseFloat(b.val()),d=parseFloat(b.attr("max")),e=parseFloat(b.attr("min")),f=b.attr("step");c&&""!==c&&"NaN"!==c||(c=0),""!==d&&"NaN"!==d||(d=""),""!==e&&"NaN"!==e||(e=0),"any"!==f&&""!==f&&void 0!==f&&"NaN"!==parseFloat(f)||(f=1),a(this).is(".plus")?d&&c>=d?b.val(d):b.val((c+parseFloat(f)).toFixed(f.getDecimals())):e&&c<=e?b.val(e):c>0&&b.val((c-parseFloat(f)).toFixed(f.getDecimals())),b.trigger("change")}),b()});
|
includes/class-wc-quantity-increment.php
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
| 3 |
-
exit; // Exit if accessed directly
|
| 4 |
-
}
|
| 5 |
-
|
| 6 |
-
class WooCommerce_Quantity_Increment_Init {
|
| 7 |
-
|
| 8 |
-
function __construct() {
|
| 9 |
-
|
| 10 |
-
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
| 11 |
-
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
public function enqueue_scripts() {
|
| 15 |
-
|
| 16 |
-
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
| 17 |
-
|
| 18 |
-
wp_register_script( 'wcqi-js', plugins_url( 'assets/js/wc-quantity-increment' . $min . '.js', plugin_dir_path( __FILE__ ) ), array( 'jquery' ) );
|
| 19 |
-
wp_register_style( 'wcqi-css', plugins_url( 'assets/css/wc-quantity-increment.css', plugin_dir_path( __FILE__ ) ) );
|
| 20 |
-
wp_register_script( 'wcqi-number-polyfill', plugins_url( 'assets/js/lib/number-polyfill.min.js', plugin_dir_path( __FILE__ ) ) );
|
| 21 |
-
|
| 22 |
-
wp_enqueue_script( 'wcqi-js' );
|
| 23 |
-
wp_enqueue_style( 'wcqi-css' );
|
| 24 |
-
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
new WooCommerce_Quantity_Increment_Init;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
languages/WooCommerce-Quantity-Increment.pot
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) 2016 WooCommerce Quantity Increment
|
| 2 |
+
# This file is distributed under the same license as the WooCommerce Quantity Increment package.
|
| 3 |
+
msgid ""
|
| 4 |
+
msgstr ""
|
| 5 |
+
"Project-Id-Version: WooCommerce Quantity Increment 1.1.0\n"
|
| 6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/WooCommerce-Quantity-"
|
| 7 |
+
"Increment\n"
|
| 8 |
+
"POT-Creation-Date: 2016-07-25 10:51:51+00:00\n"
|
| 9 |
+
"MIME-Version: 1.0\n"
|
| 10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
| 11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
| 12 |
+
"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
|
| 13 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
| 14 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
| 15 |
+
|
| 16 |
+
#: woocommerce-quantity-increment.php:112
|
| 17 |
+
msgid "WooCommerce Quantity Increment requires the %s 2.3 or higher to work!"
|
| 18 |
+
msgstr ""
|
| 19 |
+
|
| 20 |
+
#: woocommerce-quantity-increment.php:112
|
| 21 |
+
msgid "WooCommerce"
|
| 22 |
+
msgstr ""
|
| 23 |
+
|
| 24 |
+
#. Plugin Name of the plugin/theme
|
| 25 |
+
msgid "WooCommerce Quantity Increment"
|
| 26 |
+
msgstr ""
|
| 27 |
+
|
| 28 |
+
#. Plugin URI of the plugin/theme
|
| 29 |
+
msgid "https://wordpress.org/plugins/woocommerce-quantity-increment/"
|
| 30 |
+
msgstr ""
|
| 31 |
+
|
| 32 |
+
#. Description of the plugin/theme
|
| 33 |
+
msgid ""
|
| 34 |
+
"WooCommerce Quantity Increment adds JavaScript powered quantity buttons to "
|
| 35 |
+
"your cart page."
|
| 36 |
+
msgstr ""
|
| 37 |
+
|
| 38 |
+
#. Author of the plugin/theme
|
| 39 |
+
msgid "Automattic, WooThemes"
|
| 40 |
+
msgstr ""
|
| 41 |
+
|
| 42 |
+
#. Author URI of the plugin/theme
|
| 43 |
+
msgid "https://woocommerce.com/"
|
| 44 |
+
msgstr ""
|
languages/woocommerce-quantity-increment-en_GB.mo
DELETED
|
Binary file
|
languages/woocommerce-quantity-increment-en_GB.po
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
msgid ""
|
| 2 |
-
msgstr ""
|
| 3 |
-
"Project-Id-Version: WooCommerce Quantity Increment\n"
|
| 4 |
-
"POT-Creation-Date: 2014-11-19 12:50+0700\n"
|
| 5 |
-
"PO-Revision-Date: 2014-11-19 12:50+0700\n"
|
| 6 |
-
"Last-Translator: Bryce <bryce@bryce.se>\n"
|
| 7 |
-
"Language-Team: WooThemes <help@woothemes.com>\n"
|
| 8 |
-
"Language: en_GB\n"
|
| 9 |
-
"MIME-Version: 1.0\n"
|
| 10 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
| 11 |
-
"Content-Transfer-Encoding: 8bit\n"
|
| 12 |
-
"X-Generator: Poedit 1.6.4\n"
|
| 13 |
-
"X-Poedit-Basepath: .\n"
|
| 14 |
-
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
| 15 |
-
"X-Poedit-KeywordsList: __;_e\n"
|
| 16 |
-
"X-Poedit-SearchPath-0: ..\n"
|
| 17 |
-
|
| 18 |
-
#: ../woocommerce-quantity-increment.php:119
|
| 19 |
-
#, php-format
|
| 20 |
-
msgid "WooCommerce Quantity Increment requires the %s 2.3 or higher to work!"
|
| 21 |
-
msgstr ""
|
| 22 |
-
|
| 23 |
-
#: ../woocommerce-quantity-increment.php:119
|
| 24 |
-
msgid "WooCommerce"
|
| 25 |
-
msgstr ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
|
@@ -1,24 +1,23 @@
|
|
| 1 |
=== Plugin Name ===
|
| 2 |
-
Contributors:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
Stable tag: 1.0.0
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
| 11 |
-
WooCommerce Quantity Increment
|
| 12 |
|
| 13 |
== Description ==
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
However, you may want to
|
| 18 |
|
| 19 |
-
It optionally includes [Number Polyfill](https://github.com/jonstipe/number-polyfill), which is a polyfill for implementing the HTML5 `<input type="number">` element in browsers that do not currently support it.
|
| 20 |
|
| 21 |
-
To include
|
| 22 |
|
| 23 |
`
|
| 24 |
add_action( 'wp_enqueue_scripts', 'wcqi_enqueue_polyfill' );
|
|
@@ -47,11 +46,10 @@ function wcs_dequeue_quantity() {
|
|
| 47 |
|
| 48 |
This will dequeue the plugin’s stylesheet.
|
| 49 |
|
| 50 |
-
== Screenshots ==
|
| 51 |
-
|
| 52 |
-
1. The Quantity Increment buttons
|
| 53 |
-
|
| 54 |
== Changelog ==
|
| 55 |
|
|
|
|
|
|
|
|
|
|
| 56 |
= 1.0 =
|
| 57 |
-
* Initial Release
|
| 1 |
=== Plugin Name ===
|
| 2 |
+
Contributors: automattic, woothemes
|
| 3 |
+
Tags: woocommerce, quantity, quantity increment, quantity buttons, spinner
|
| 4 |
+
Requires at least: 4.1
|
| 5 |
+
Tested up to: 4.5
|
| 6 |
+
Stable tag: 1.1.0
|
|
|
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
|
| 10 |
+
WooCommerce Quantity Increment adds JavaScript powered quantity buttons to your cart page.
|
| 11 |
|
| 12 |
== Description ==
|
| 13 |
|
| 14 |
+
WooCommerce uses number inputs for the cart quantities by default, as most browsers now support `<input type="number" />`.
|
| 15 |
|
| 16 |
+
However, you may want to have JavaScript powered inputs if you want greater control over appearance. Simply install and activate this plugin to do so.
|
| 17 |
|
| 18 |
+
It optionally includes a [Number Polyfill](https://github.com/jonstipe/number-polyfill), which is a polyfill for implementing the HTML5 `<input type="number">` element in browsers that do not currently support it.
|
| 19 |
|
| 20 |
+
To include this, add the following code to your theme's `functions.php` file:
|
| 21 |
|
| 22 |
`
|
| 23 |
add_action( 'wp_enqueue_scripts', 'wcqi_enqueue_polyfill' );
|
| 46 |
|
| 47 |
This will dequeue the plugin’s stylesheet.
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
== Changelog ==
|
| 50 |
|
| 51 |
+
= 1.1.0 =
|
| 52 |
+
* Updated to work with the WooCommerce 2.6 cart ajax script.
|
| 53 |
+
|
| 54 |
= 1.0 =
|
| 55 |
+
* Initial Release
|
woocommerce-quantity-increment.php
CHANGED
|
@@ -1,126 +1,118 @@
|
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Plugin Name: WooCommerce Quantity Increment
|
| 4 |
-
* Plugin URI: https://
|
| 5 |
-
* Description:
|
| 6 |
-
* Version: 1.
|
| 7 |
-
* Author:
|
| 8 |
-
* Author URI:
|
| 9 |
* Text Domain: woocommerce-quantity-increment
|
| 10 |
* Domain Path: /languages
|
| 11 |
*/
|
| 12 |
-
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) {
|
| 14 |
exit;
|
| 15 |
}
|
| 16 |
|
| 17 |
-
if ( ! class_exists( 'WooCommerce_Quantity_Increment' ) )
|
| 18 |
-
|
| 19 |
-
/**
|
| 20 |
-
* WooCommerce_Quantity_Increment main class.
|
| 21 |
-
*/
|
| 22 |
-
class WooCommerce_Quantity_Increment {
|
| 23 |
|
| 24 |
/**
|
| 25 |
-
*
|
| 26 |
-
*
|
| 27 |
-
* @var string
|
| 28 |
*/
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
$this
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
self::$instance
|
| 67 |
}
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
-
/**
|
| 114 |
-
* WooCommerce fallback notice.
|
| 115 |
-
*
|
| 116 |
-
* @return string
|
| 117 |
-
*/
|
| 118 |
-
public function woocommerce_missing_notice() {
|
| 119 |
-
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Quantity Increment requires the %s 2.3 or higher to work!', 'woocommerce-quantity-increment' ), '<a href="http://www.woothemes.com/woocommerce/" target="_blank">' . __( 'WooCommerce', 'woocommerce-quantity-increment' ) . '</a>' ) . '</p></div>';
|
| 120 |
}
|
| 121 |
|
|
|
|
| 122 |
}
|
| 123 |
-
|
| 124 |
-
add_action( 'plugins_loaded', array( 'WooCommerce_Quantity_Increment', 'get_instance' ), 0 );
|
| 125 |
-
|
| 126 |
-
endif;
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Plugin Name: WooCommerce Quantity Increment
|
| 4 |
+
* Plugin URI: https://wordpress.org/plugins/woocommerce-quantity-increment/
|
| 5 |
+
* Description: WooCommerce Quantity Increment adds JavaScript powered quantity buttons to your cart page.
|
| 6 |
+
* Version: 1.1.0
|
| 7 |
+
* Author: Automattic, WooThemes
|
| 8 |
+
* Author URI: https://woocommerce.com/
|
| 9 |
* Text Domain: woocommerce-quantity-increment
|
| 10 |
* Domain Path: /languages
|
| 11 |
*/
|
|
|
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) {
|
| 13 |
exit;
|
| 14 |
}
|
| 15 |
|
| 16 |
+
if ( ! class_exists( 'WooCommerce_Quantity_Increment' ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
/**
|
| 19 |
+
* WooCommerce_Quantity_Increment main class.
|
|
|
|
|
|
|
| 20 |
*/
|
| 21 |
+
class WooCommerce_Quantity_Increment {
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Plugin version.
|
| 25 |
+
*
|
| 26 |
+
* @var string
|
| 27 |
+
*/
|
| 28 |
+
const VERSION = '1.1.0';
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Instance of this class.
|
| 32 |
+
*
|
| 33 |
+
* @var object
|
| 34 |
+
*/
|
| 35 |
+
protected static $instance = null;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Initialize the plugin.
|
| 39 |
+
*/
|
| 40 |
+
private function __construct() {
|
| 41 |
+
// Load plugin text domain
|
| 42 |
+
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
|
| 43 |
+
|
| 44 |
+
// Checks with WooCommerce is installed.
|
| 45 |
+
if ( self::is_wc_version_gte_2_3() ) {
|
| 46 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
| 47 |
+
} else {
|
| 48 |
+
add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
|
| 49 |
+
}
|
| 50 |
}
|
| 51 |
|
| 52 |
+
/**
|
| 53 |
+
* Return an instance of this class.
|
| 54 |
+
*
|
| 55 |
+
* @return object A single instance of this class.
|
| 56 |
+
*/
|
| 57 |
+
public static function get_instance() {
|
| 58 |
+
// If the single instance hasn't been set, set it now.
|
| 59 |
+
if ( null == self::$instance ) {
|
| 60 |
+
self::$instance = new self;
|
| 61 |
+
}
|
| 62 |
+
return self::$instance;
|
| 63 |
}
|
| 64 |
|
| 65 |
+
/**
|
| 66 |
+
* Load the plugin text domain for translation.
|
| 67 |
+
*
|
| 68 |
+
* @return void
|
| 69 |
+
*/
|
| 70 |
+
public function load_plugin_textdomain() {
|
| 71 |
+
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-quantity-increment' );
|
| 72 |
+
load_textdomain( 'woocommerce-quantity-increment', trailingslashit( WP_LANG_DIR ) . 'woocommerce-quantity-increment/woocommerce-quantity-increment-' . $locale . '.mo' );
|
| 73 |
+
load_plugin_textdomain( 'woocommerce-quantity-increment', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
| 74 |
+
}
|
| 75 |
|
| 76 |
+
/**
|
| 77 |
+
* Helper method to get the version of the currently installed WooCommerce
|
| 78 |
+
*
|
| 79 |
+
* @since 1.0.0
|
| 80 |
+
* @return string woocommerce version number or null
|
| 81 |
+
*/
|
| 82 |
+
private static function get_wc_version() {
|
| 83 |
+
return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null;
|
| 84 |
+
}
|
| 85 |
|
| 86 |
+
/**
|
| 87 |
+
* Returns true if the installed version of WooCommerce is 2.3 or greater
|
| 88 |
+
*
|
| 89 |
+
* @since 1.0.0
|
| 90 |
+
* @return boolean true if the installed version of WooCommerce is 2.3 or greater
|
| 91 |
+
*/
|
| 92 |
+
public static function is_wc_version_gte_2_3() {
|
| 93 |
+
return self::get_wc_version() && version_compare( self::get_wc_version(), '2.3', '>=' );
|
| 94 |
+
}
|
| 95 |
|
| 96 |
+
/**
|
| 97 |
+
* Enqueue scripts
|
| 98 |
+
*/
|
| 99 |
+
public function enqueue_scripts() {
|
| 100 |
+
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
| 101 |
+
wp_enqueue_script( 'wcqi-js', plugins_url( 'assets/js/wc-quantity-increment' . $min . '.js', __FILE__ ), array( 'jquery' ) );
|
| 102 |
+
wp_enqueue_style( 'wcqi-css', plugins_url( 'assets/css/wc-quantity-increment.css', __FILE__ ) );
|
| 103 |
+
wp_register_script( 'wcqi-number-polyfill', plugins_url( 'assets/js/lib/number-polyfill.min.js', __FILE__ ) );
|
| 104 |
+
}
|
| 105 |
|
| 106 |
+
/**
|
| 107 |
+
* WooCommerce fallback notice.
|
| 108 |
+
*
|
| 109 |
+
* @return string
|
| 110 |
+
*/
|
| 111 |
+
public function woocommerce_missing_notice() {
|
| 112 |
+
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Quantity Increment requires the %s 2.3 or higher to work!', 'woocommerce-quantity-increment' ), '<a href="http://www.woothemes.com/woocommerce/" target="_blank">' . __( 'WooCommerce', 'woocommerce-quantity-increment' ) . '</a>' ) . '</p></div>';
|
| 113 |
+
}
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
}
|
| 116 |
|
| 117 |
+
add_action( 'plugins_loaded', array( 'WooCommerce_Quantity_Increment', 'get_instance' ), 0 );
|
| 118 |
}
|
|
|
|
|
|
|
|
|
|
|
|
wordpress_org_assets/banner-1544x500.png
ADDED
|
Binary file
|
wordpress_org_assets/banner-772x250.png
ADDED
|
Binary file
|
wordpress_org_assets/icon-128x128.png
ADDED
|
Binary file
|
wordpress_org_assets/icon-256x256.png
ADDED
|
Binary file
|
wordpress_org_assets/wcqi.sketch
ADDED
|
Binary file
|
