Version Description
- Fix the issue of product attributes are not saved.
- Restore attribute type to "Select" if the plugin is deactivated.
Download this release
Release Info
Developer | themealien |
Plugin | Variation Swatches for WooCommerce |
Version | 1.0.4 |
Comparing to | |
See all releases |
Code changes from version 1.0.3 to 1.0.4
- assets/css/admin.css +62 -62
- assets/css/frontend.css +3 -2
- assets/js/admin.js +143 -143
- includes/class-admin-product.php +184 -0
- includes/class-admin.php +228 -390
- includes/class-frontend.php +161 -161
- includes/class-variation-swatches.php +141 -0
- languages/wcvs.pot +127 -127
- readme.txt +92 -88
- uninstall.php +15 -15
- variation-swatches-for-woocommerce.php +145 -181
assets/css/admin.css
CHANGED
@@ -1,62 +1,62 @@
|
|
1 |
-
.swatch-preview {
|
2 |
-
width: 44px;
|
3 |
-
height: 44px;
|
4 |
-
line-height: 44px;
|
5 |
-
text-align: center;
|
6 |
-
font-weight: 700;
|
7 |
-
border: 1px solid #ccc;
|
8 |
-
}
|
9 |
-
|
10 |
-
.tawcvs-modal-container {
|
11 |
-
position: relative;
|
12 |
-
display: none;
|
13 |
-
}
|
14 |
-
|
15 |
-
.tawcvs-modal {
|
16 |
-
transform: translate(-50%, -50%);
|
17 |
-
position: fixed;
|
18 |
-
top: 50%;
|
19 |
-
left: 50%;
|
20 |
-
width: 360px;
|
21 |
-
max-width: 90%;
|
22 |
-
z-index: 159990;
|
23 |
-
background-color: #fcfcfc;
|
24 |
-
}
|
25 |
-
|
26 |
-
.tawcvs-modal input.error {
|
27 |
-
border-color: #dc3232;
|
28 |
-
}
|
29 |
-
|
30 |
-
.tawcvs-modal-header,
|
31 |
-
.tawcvs-modal-content,
|
32 |
-
.tawcvs-modal-footer {
|
33 |
-
padding: 20px;
|
34 |
-
}
|
35 |
-
|
36 |
-
.tawcvs-modal-header {
|
37 |
-
padding-top: 0;
|
38 |
-
padding-bottom: 0;
|
39 |
-
}
|
40 |
-
|
41 |
-
.tawcvs-modal-content {
|
42 |
-
border-top: 1px solid #ddd;
|
43 |
-
border-bottom: 1px solid #ddd;
|
44 |
-
background-color: #fff;
|
45 |
-
}
|
46 |
-
|
47 |
-
.tawcvs-modal-footer {
|
48 |
-
text-align: right;
|
49 |
-
}
|
50 |
-
|
51 |
-
.tawcvs-modal-footer .message,
|
52 |
-
.tawcvs-modal-footer .spinner {
|
53 |
-
float: left;
|
54 |
-
}
|
55 |
-
|
56 |
-
.tawcvs-modal-footer .message.error {
|
57 |
-
color: #dc3232;
|
58 |
-
}
|
59 |
-
|
60 |
-
.tawcvs-modal-footer .message.success {
|
61 |
-
color: #46b450;
|
62 |
-
}
|
1 |
+
.swatch-preview {
|
2 |
+
width: 44px;
|
3 |
+
height: 44px;
|
4 |
+
line-height: 44px;
|
5 |
+
text-align: center;
|
6 |
+
font-weight: 700;
|
7 |
+
border: 1px solid #ccc;
|
8 |
+
}
|
9 |
+
|
10 |
+
.tawcvs-modal-container {
|
11 |
+
position: relative;
|
12 |
+
display: none;
|
13 |
+
}
|
14 |
+
|
15 |
+
.tawcvs-modal {
|
16 |
+
transform: translate(-50%, -50%);
|
17 |
+
position: fixed;
|
18 |
+
top: 50%;
|
19 |
+
left: 50%;
|
20 |
+
width: 360px;
|
21 |
+
max-width: 90%;
|
22 |
+
z-index: 159990;
|
23 |
+
background-color: #fcfcfc;
|
24 |
+
}
|
25 |
+
|
26 |
+
.tawcvs-modal input.error {
|
27 |
+
border-color: #dc3232;
|
28 |
+
}
|
29 |
+
|
30 |
+
.tawcvs-modal-header,
|
31 |
+
.tawcvs-modal-content,
|
32 |
+
.tawcvs-modal-footer {
|
33 |
+
padding: 20px;
|
34 |
+
}
|
35 |
+
|
36 |
+
.tawcvs-modal-header {
|
37 |
+
padding-top: 0;
|
38 |
+
padding-bottom: 0;
|
39 |
+
}
|
40 |
+
|
41 |
+
.tawcvs-modal-content {
|
42 |
+
border-top: 1px solid #ddd;
|
43 |
+
border-bottom: 1px solid #ddd;
|
44 |
+
background-color: #fff;
|
45 |
+
}
|
46 |
+
|
47 |
+
.tawcvs-modal-footer {
|
48 |
+
text-align: right;
|
49 |
+
}
|
50 |
+
|
51 |
+
.tawcvs-modal-footer .message,
|
52 |
+
.tawcvs-modal-footer .spinner {
|
53 |
+
float: left;
|
54 |
+
}
|
55 |
+
|
56 |
+
.tawcvs-modal-footer .message.error {
|
57 |
+
color: #dc3232;
|
58 |
+
}
|
59 |
+
|
60 |
+
.tawcvs-modal-footer .message.success {
|
61 |
+
color: #46b450;
|
62 |
+
}
|
assets/css/frontend.css
CHANGED
@@ -43,10 +43,11 @@
|
|
43 |
|
44 |
.tawcvs-swatches .swatch-color {
|
45 |
text-indent: -9999px;
|
|
|
46 |
}
|
47 |
|
48 |
.tawcvs-swatches .swatch-color.selected {
|
49 |
-
border-color:
|
50 |
}
|
51 |
|
52 |
.tawcvs-swatches .swatch-color.selected:before {
|
@@ -57,7 +58,7 @@
|
|
57 |
width: 6px;
|
58 |
height: 10px;
|
59 |
display: block;
|
60 |
-
border: solid #
|
61 |
border-width: 0 2px 2px 0;
|
62 |
position: absolute;
|
63 |
top: 8px;
|
43 |
|
44 |
.tawcvs-swatches .swatch-color {
|
45 |
text-indent: -9999px;
|
46 |
+
border: 2px solid #ccc;
|
47 |
}
|
48 |
|
49 |
.tawcvs-swatches .swatch-color.selected {
|
50 |
+
border-color: #333;
|
51 |
}
|
52 |
|
53 |
.tawcvs-swatches .swatch-color.selected:before {
|
58 |
width: 6px;
|
59 |
height: 10px;
|
60 |
display: block;
|
61 |
+
border: solid #eee;
|
62 |
border-width: 0 2px 2px 0;
|
63 |
position: absolute;
|
64 |
top: 8px;
|
assets/js/admin.js
CHANGED
@@ -1,143 +1,143 @@
|
|
1 |
-
var frame,
|
2 |
-
tawcvs = tawcvs || {};
|
3 |
-
|
4 |
-
jQuery( document ).ready( function ( $ ) {
|
5 |
-
'use strict';
|
6 |
-
var wp = window.wp,
|
7 |
-
$body = $( 'body' );
|
8 |
-
|
9 |
-
$( '#term-color' ).wpColorPicker();
|
10 |
-
|
11 |
-
// Update attribute image
|
12 |
-
$body.on( 'click', '.tawcvs-upload-image-button', function ( event ) {
|
13 |
-
event.preventDefault();
|
14 |
-
|
15 |
-
var $button = $( this );
|
16 |
-
|
17 |
-
// If the media frame already exists, reopen it.
|
18 |
-
if ( frame ) {
|
19 |
-
frame.open();
|
20 |
-
return;
|
21 |
-
}
|
22 |
-
|
23 |
-
// Create the media frame.
|
24 |
-
frame = wp.media.frames.downloadable_file = wp.media( {
|
25 |
-
title : tawcvs.i18n.mediaTitle,
|
26 |
-
button : {
|
27 |
-
text: tawcvs.i18n.mediaButton
|
28 |
-
},
|
29 |
-
multiple: false
|
30 |
-
} );
|
31 |
-
|
32 |
-
// When an image is selected, run a callback.
|
33 |
-
frame.on( 'select', function () {
|
34 |
-
var attachment = frame.state().get( 'selection' ).first().toJSON();
|
35 |
-
|
36 |
-
$button.siblings( 'input.tawcvs-term-image' ).val( attachment.id );
|
37 |
-
$button.siblings( '.tawcvs-remove-image-button' ).show();
|
38 |
-
$button.parent().prev( '.tawcvs-term-image-thumbnail' ).find( 'img' ).attr( 'src', attachment.sizes.thumbnail.url );
|
39 |
-
} );
|
40 |
-
|
41 |
-
// Finally, open the modal.
|
42 |
-
frame.open();
|
43 |
-
|
44 |
-
} ).on( 'click', '.tawcvs-remove-image-button', function () {
|
45 |
-
var $button = $( this );
|
46 |
-
|
47 |
-
$button.siblings( 'input.tawcvs-term-image' ).val( '' );
|
48 |
-
$button.siblings( '.tawcvs-remove-image-button' ).show();
|
49 |
-
$button.parent().prev( '.tawcvs-term-image-thumbnail' ).find( 'img' ).attr( 'src', tawcvs.placeholder );
|
50 |
-
|
51 |
-
return false;
|
52 |
-
} );
|
53 |
-
|
54 |
-
// Toggle add new attribute term modal
|
55 |
-
var $modal = $( '#tawcvs-modal-container' ),
|
56 |
-
$spinner = $modal.find( '.spinner' ),
|
57 |
-
$msg = $modal.find( '.message' ),
|
58 |
-
$metabox = null;
|
59 |
-
|
60 |
-
$body.on( 'click', '.tawcvs_add_new_attribute', function ( e ) {
|
61 |
-
e.preventDefault();
|
62 |
-
var $button = $( this ),
|
63 |
-
taxInputTemplate = wp.template( 'tawcvs-input-tax' ),
|
64 |
-
data = {
|
65 |
-
type: $button.data( 'type' ),
|
66 |
-
tax : $button.closest( '.woocommerce_attribute' ).data( 'taxonomy' )
|
67 |
-
};
|
68 |
-
|
69 |
-
// Insert input
|
70 |
-
$modal.find( '.tawcvs-term-swatch' ).html( $( '#tmpl-tawcvs-input-' + data.type ).html() );
|
71 |
-
$modal.find( '.tawcvs-term-tax' ).html( taxInputTemplate( data ) );
|
72 |
-
|
73 |
-
if ( 'color' == data.type ) {
|
74 |
-
$modal.find( 'input.tawcvs-input-color' ).wpColorPicker();
|
75 |
-
}
|
76 |
-
|
77 |
-
$metabox = $button.closest( '.woocommerce_attribute.wc-metabox' );
|
78 |
-
$modal.show();
|
79 |
-
} ).on( 'click', '.tawcvs-modal-close, .tawcvs-modal-backdrop', function ( e ) {
|
80 |
-
e.preventDefault();
|
81 |
-
|
82 |
-
closeModal();
|
83 |
-
} );
|
84 |
-
|
85 |
-
// Send ajax request to add new attribute term
|
86 |
-
$body.on( 'click', '.tawcvs-new-attribute-submit', function ( e ) {
|
87 |
-
e.preventDefault();
|
88 |
-
|
89 |
-
var $button = $( this ),
|
90 |
-
type = $button.data( 'type' ),
|
91 |
-
error = false,
|
92 |
-
data = {};
|
93 |
-
|
94 |
-
// Validate
|
95 |
-
$modal.find( '.tawcvs-input' ).each( function () {
|
96 |
-
var $this = $( this );
|
97 |
-
|
98 |
-
if ( $this.attr( 'name' ) != 'slug' && !$this.val() ) {
|
99 |
-
$this.addClass( 'error' );
|
100 |
-
error = true;
|
101 |
-
} else {
|
102 |
-
$this.removeClass( 'error' );
|
103 |
-
}
|
104 |
-
|
105 |
-
data[$this.attr( 'name' )] = $this.val();
|
106 |
-
} );
|
107 |
-
|
108 |
-
if ( error ) {
|
109 |
-
return;
|
110 |
-
}
|
111 |
-
|
112 |
-
// Send ajax request
|
113 |
-
$spinner.addClass( 'is-active' );
|
114 |
-
$msg.hide();
|
115 |
-
wp.ajax.send( 'tawcvs_add_new_attribute', {
|
116 |
-
data : data,
|
117 |
-
error : function ( res ) {
|
118 |
-
$spinner.removeClass( 'is-active' );
|
119 |
-
$msg.addClass( 'error' ).text( res ).show();
|
120 |
-
},
|
121 |
-
success: function ( res ) {
|
122 |
-
$spinner.removeClass( 'is-active' );
|
123 |
-
$msg.addClass( 'success' ).text( res.msg ).show();
|
124 |
-
|
125 |
-
$metabox.find( 'select.attribute_values' ).append( '<option value="' + res.id + '" selected="selected">' + res.name + '</option>' );
|
126 |
-
$metabox.find( 'select.attribute_values' ).change();
|
127 |
-
|
128 |
-
closeModal();
|
129 |
-
}
|
130 |
-
} );
|
131 |
-
} );
|
132 |
-
|
133 |
-
/**
|
134 |
-
* Close modal
|
135 |
-
*/
|
136 |
-
function closeModal() {
|
137 |
-
$modal.find( '.tawcvs-term-name input, .tawcvs-term-slug input' ).val( '' );
|
138 |
-
$spinner.removeClass( 'is-active' );
|
139 |
-
$msg.removeClass( 'error success' ).hide();
|
140 |
-
$modal.hide();
|
141 |
-
}
|
142 |
-
} );
|
143 |
-
|
1 |
+
var frame,
|
2 |
+
tawcvs = tawcvs || {};
|
3 |
+
|
4 |
+
jQuery( document ).ready( function ( $ ) {
|
5 |
+
'use strict';
|
6 |
+
var wp = window.wp,
|
7 |
+
$body = $( 'body' );
|
8 |
+
|
9 |
+
$( '#term-color' ).wpColorPicker();
|
10 |
+
|
11 |
+
// Update attribute image
|
12 |
+
$body.on( 'click', '.tawcvs-upload-image-button', function ( event ) {
|
13 |
+
event.preventDefault();
|
14 |
+
|
15 |
+
var $button = $( this );
|
16 |
+
|
17 |
+
// If the media frame already exists, reopen it.
|
18 |
+
if ( frame ) {
|
19 |
+
frame.open();
|
20 |
+
return;
|
21 |
+
}
|
22 |
+
|
23 |
+
// Create the media frame.
|
24 |
+
frame = wp.media.frames.downloadable_file = wp.media( {
|
25 |
+
title : tawcvs.i18n.mediaTitle,
|
26 |
+
button : {
|
27 |
+
text: tawcvs.i18n.mediaButton
|
28 |
+
},
|
29 |
+
multiple: false
|
30 |
+
} );
|
31 |
+
|
32 |
+
// When an image is selected, run a callback.
|
33 |
+
frame.on( 'select', function () {
|
34 |
+
var attachment = frame.state().get( 'selection' ).first().toJSON();
|
35 |
+
|
36 |
+
$button.siblings( 'input.tawcvs-term-image' ).val( attachment.id );
|
37 |
+
$button.siblings( '.tawcvs-remove-image-button' ).show();
|
38 |
+
$button.parent().prev( '.tawcvs-term-image-thumbnail' ).find( 'img' ).attr( 'src', attachment.sizes.thumbnail.url );
|
39 |
+
} );
|
40 |
+
|
41 |
+
// Finally, open the modal.
|
42 |
+
frame.open();
|
43 |
+
|
44 |
+
} ).on( 'click', '.tawcvs-remove-image-button', function () {
|
45 |
+
var $button = $( this );
|
46 |
+
|
47 |
+
$button.siblings( 'input.tawcvs-term-image' ).val( '' );
|
48 |
+
$button.siblings( '.tawcvs-remove-image-button' ).show();
|
49 |
+
$button.parent().prev( '.tawcvs-term-image-thumbnail' ).find( 'img' ).attr( 'src', tawcvs.placeholder );
|
50 |
+
|
51 |
+
return false;
|
52 |
+
} );
|
53 |
+
|
54 |
+
// Toggle add new attribute term modal
|
55 |
+
var $modal = $( '#tawcvs-modal-container' ),
|
56 |
+
$spinner = $modal.find( '.spinner' ),
|
57 |
+
$msg = $modal.find( '.message' ),
|
58 |
+
$metabox = null;
|
59 |
+
|
60 |
+
$body.on( 'click', '.tawcvs_add_new_attribute', function ( e ) {
|
61 |
+
e.preventDefault();
|
62 |
+
var $button = $( this ),
|
63 |
+
taxInputTemplate = wp.template( 'tawcvs-input-tax' ),
|
64 |
+
data = {
|
65 |
+
type: $button.data( 'type' ),
|
66 |
+
tax : $button.closest( '.woocommerce_attribute' ).data( 'taxonomy' )
|
67 |
+
};
|
68 |
+
|
69 |
+
// Insert input
|
70 |
+
$modal.find( '.tawcvs-term-swatch' ).html( $( '#tmpl-tawcvs-input-' + data.type ).html() );
|
71 |
+
$modal.find( '.tawcvs-term-tax' ).html( taxInputTemplate( data ) );
|
72 |
+
|
73 |
+
if ( 'color' == data.type ) {
|
74 |
+
$modal.find( 'input.tawcvs-input-color' ).wpColorPicker();
|
75 |
+
}
|
76 |
+
|
77 |
+
$metabox = $button.closest( '.woocommerce_attribute.wc-metabox' );
|
78 |
+
$modal.show();
|
79 |
+
} ).on( 'click', '.tawcvs-modal-close, .tawcvs-modal-backdrop', function ( e ) {
|
80 |
+
e.preventDefault();
|
81 |
+
|
82 |
+
closeModal();
|
83 |
+
} );
|
84 |
+
|
85 |
+
// Send ajax request to add new attribute term
|
86 |
+
$body.on( 'click', '.tawcvs-new-attribute-submit', function ( e ) {
|
87 |
+
e.preventDefault();
|
88 |
+
|
89 |
+
var $button = $( this ),
|
90 |
+
type = $button.data( 'type' ),
|
91 |
+
error = false,
|
92 |
+
data = {};
|
93 |
+
|
94 |
+
// Validate
|
95 |
+
$modal.find( '.tawcvs-input' ).each( function () {
|
96 |
+
var $this = $( this );
|
97 |
+
|
98 |
+
if ( $this.attr( 'name' ) != 'slug' && !$this.val() ) {
|
99 |
+
$this.addClass( 'error' );
|
100 |
+
error = true;
|
101 |
+
} else {
|
102 |
+
$this.removeClass( 'error' );
|
103 |
+
}
|
104 |
+
|
105 |
+
data[$this.attr( 'name' )] = $this.val();
|
106 |
+
} );
|
107 |
+
|
108 |
+
if ( error ) {
|
109 |
+
return;
|
110 |
+
}
|
111 |
+
|
112 |
+
// Send ajax request
|
113 |
+
$spinner.addClass( 'is-active' );
|
114 |
+
$msg.hide();
|
115 |
+
wp.ajax.send( 'tawcvs_add_new_attribute', {
|
116 |
+
data : data,
|
117 |
+
error : function ( res ) {
|
118 |
+
$spinner.removeClass( 'is-active' );
|
119 |
+
$msg.addClass( 'error' ).text( res ).show();
|
120 |
+
},
|
121 |
+
success: function ( res ) {
|
122 |
+
$spinner.removeClass( 'is-active' );
|
123 |
+
$msg.addClass( 'success' ).text( res.msg ).show();
|
124 |
+
|
125 |
+
$metabox.find( 'select.attribute_values' ).append( '<option value="' + res.id + '" selected="selected">' + res.name + '</option>' );
|
126 |
+
$metabox.find( 'select.attribute_values' ).change();
|
127 |
+
|
128 |
+
closeModal();
|
129 |
+
}
|
130 |
+
} );
|
131 |
+
} );
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Close modal
|
135 |
+
*/
|
136 |
+
function closeModal() {
|
137 |
+
$modal.find( '.tawcvs-term-name input, .tawcvs-term-slug input' ).val( '' );
|
138 |
+
$spinner.removeClass( 'is-active' );
|
139 |
+
$msg.removeClass( 'error success' ).hide();
|
140 |
+
$modal.hide();
|
141 |
+
}
|
142 |
+
} );
|
143 |
+
|
includes/class-admin-product.php
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class TA_WC_Variation_Swatches_Admin_Product
|
5 |
+
*/
|
6 |
+
class TA_WC_Variation_Swatches_Admin_Product {
|
7 |
+
/**
|
8 |
+
* Class constructor.
|
9 |
+
*/
|
10 |
+
public function __construct() {
|
11 |
+
add_action( 'woocommerce_product_option_terms', array( $this, 'product_option_terms' ), 10, 2 );
|
12 |
+
|
13 |
+
add_action( 'wp_ajax_tawcvs_add_new_attribute', array( $this, 'add_new_attribute_ajax' ) );
|
14 |
+
add_action( 'admin_footer', array( $this, 'add_attribute_term_template' ) );
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Add selector for extra attribute types
|
19 |
+
*
|
20 |
+
* @param $taxonomy
|
21 |
+
* @param $index
|
22 |
+
*/
|
23 |
+
public function product_option_terms( $taxonomy, $index ) {
|
24 |
+
if ( ! array_key_exists( $taxonomy->attribute_type, TA_WCVS()->types ) ) {
|
25 |
+
return;
|
26 |
+
}
|
27 |
+
|
28 |
+
$taxonomy_name = wc_attribute_taxonomy_name( $taxonomy->attribute_name );
|
29 |
+
global $thepostid;
|
30 |
+
|
31 |
+
$product_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : $thepostid;
|
32 |
+
?>
|
33 |
+
|
34 |
+
<select multiple="multiple" data-placeholder="<?php esc_attr_e( 'Select terms', 'wcvs' ); ?>" class="multiselect attribute_values wc-enhanced-select" name="attribute_values[<?php echo $index; ?>][]">
|
35 |
+
<?php
|
36 |
+
|
37 |
+
$all_terms = get_terms( $taxonomy_name, apply_filters( 'woocommerce_product_attribute_terms', array( 'orderby' => 'name', 'hide_empty' => false ) ) );
|
38 |
+
if ( $all_terms ) {
|
39 |
+
foreach ( $all_terms as $term ) {
|
40 |
+
echo '<option value="' . esc_attr( $term->term_id ) . '" ' . selected( has_term( absint( $term->term_id ), $taxonomy_name, $product_id ), true, false ) . '>' . esc_attr( apply_filters( 'woocommerce_product_attribute_term_name', $term->name, $term ) ) . '</option>';
|
41 |
+
}
|
42 |
+
}
|
43 |
+
?>
|
44 |
+
</select>
|
45 |
+
<button class="button plus select_all_attributes"><?php esc_html_e( 'Select all', 'wcvs' ); ?></button>
|
46 |
+
<button class="button minus select_no_attributes"><?php esc_html_e( 'Select none', 'wcvs' ); ?></button>
|
47 |
+
<button class="button fr plus tawcvs_add_new_attribute" data-type="<?php echo $taxonomy->attribute_type ?>"><?php esc_html_e( 'Add new', 'wcvs' ); ?></button>
|
48 |
+
|
49 |
+
<?php
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Ajax function handles adding new attribute term
|
54 |
+
*/
|
55 |
+
public function add_new_attribute_ajax() {
|
56 |
+
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
57 |
+
$tax = isset( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : '';
|
58 |
+
$type = isset( $_POST['type'] ) ? $_POST['type'] : '';
|
59 |
+
$name = isset( $_POST['name'] ) ? $_POST['name'] : '';
|
60 |
+
$slug = isset( $_POST['slug'] ) ? $_POST['slug'] : '';
|
61 |
+
$swatch = isset( $_POST['swatch'] ) ? $_POST['swatch'] : '';
|
62 |
+
|
63 |
+
if ( ! wp_verify_nonce( $nonce, '_tawcvs_create_attribute' ) ) {
|
64 |
+
wp_send_json_error( esc_html__( 'Wrong request', 'wcvs' ) );
|
65 |
+
}
|
66 |
+
|
67 |
+
if ( empty( $name ) || empty( $swatch ) || empty( $tax ) || empty( $type ) ) {
|
68 |
+
wp_send_json_error( esc_html__( 'Not enough data', 'wcvs' ) );
|
69 |
+
}
|
70 |
+
|
71 |
+
if ( ! taxonomy_exists( $tax ) ) {
|
72 |
+
wp_send_json_error( esc_html__( 'Taxonomy is not exists', 'wcvs' ) );
|
73 |
+
}
|
74 |
+
|
75 |
+
if ( term_exists( $_POST['name'], $_POST['tax'] ) ) {
|
76 |
+
wp_send_json_error( esc_html__( 'This term is exists', 'wcvs' ) );
|
77 |
+
}
|
78 |
+
|
79 |
+
$term = wp_insert_term( $name, $tax, array( 'slug' => $slug ) );
|
80 |
+
|
81 |
+
if ( is_wp_error( $term ) ) {
|
82 |
+
wp_send_json_error( $term->get_error_message() );
|
83 |
+
} else {
|
84 |
+
$term = get_term_by( 'id', $term['term_id'], $tax );
|
85 |
+
update_term_meta( $term->term_id, $type, $swatch );
|
86 |
+
}
|
87 |
+
|
88 |
+
wp_send_json_success(
|
89 |
+
array(
|
90 |
+
'msg' => esc_html__( 'Added successfully', 'wcvs' ),
|
91 |
+
'id' => $term->term_id,
|
92 |
+
'slug' => $term->slug,
|
93 |
+
'name' => $term->name,
|
94 |
+
)
|
95 |
+
);
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Print HTML of modal at admin footer and add js templates
|
100 |
+
*/
|
101 |
+
public function add_attribute_term_template() {
|
102 |
+
global $pagenow, $post;
|
103 |
+
|
104 |
+
if ( $pagenow != 'post.php' || ( isset( $post ) && get_post_type( $post->ID ) != 'product' ) ) {
|
105 |
+
return;
|
106 |
+
}
|
107 |
+
?>
|
108 |
+
|
109 |
+
<div id="tawcvs-modal-container" class="tawcvs-modal-container">
|
110 |
+
<div class="tawcvs-modal">
|
111 |
+
<button type="button" class="button-link media-modal-close tawcvs-modal-close">
|
112 |
+
<span class="media-modal-icon"></span></button>
|
113 |
+
<div class="tawcvs-modal-header"><h2><?php esc_html_e( 'Add new term', 'wcvs' ) ?></h2></div>
|
114 |
+
<div class="tawcvs-modal-content">
|
115 |
+
<p class="tawcvs-term-name">
|
116 |
+
<label>
|
117 |
+
<?php esc_html_e( 'Name', 'wcvs' ) ?>
|
118 |
+
<input type="text" class="widefat tawcvs-input" name="name">
|
119 |
+
</label>
|
120 |
+
</p>
|
121 |
+
<p class="tawcvs-term-slug">
|
122 |
+
<label>
|
123 |
+
<?php esc_html_e( 'Slug', 'wcvs' ) ?>
|
124 |
+
<input type="text" class="widefat tawcvs-input" name="slug">
|
125 |
+
</label>
|
126 |
+
</p>
|
127 |
+
<div class="tawcvs-term-swatch">
|
128 |
+
|
129 |
+
</div>
|
130 |
+
<div class="hidden tawcvs-term-tax"></div>
|
131 |
+
|
132 |
+
<input type="hidden" class="tawcvs-input" name="nonce" value="<?php echo wp_create_nonce( '_tawcvs_create_attribute' ) ?>">
|
133 |
+
</div>
|
134 |
+
<div class="tawcvs-modal-footer">
|
135 |
+
<button class="button button-secondary tawcvs-modal-close"><?php esc_html_e( 'Cancel', 'wcvs' ) ?></button>
|
136 |
+
<button class="button button-primary tawcvs-new-attribute-submit"><?php esc_html_e( 'Add New', 'wcvs' ) ?></button>
|
137 |
+
<span class="message"></span>
|
138 |
+
<span class="spinner"></span>
|
139 |
+
</div>
|
140 |
+
</div>
|
141 |
+
<div class="tawcvs-modal-backdrop media-modal-backdrop"></div>
|
142 |
+
</div>
|
143 |
+
|
144 |
+
<script type="text/template" id="tmpl-tawcvs-input-color">
|
145 |
+
|
146 |
+
<label><?php esc_html_e( 'Color', 'wcvs' ) ?></label><br>
|
147 |
+
<input type="text" class="tawcvs-input tawcvs-input-color" name="swatch">
|
148 |
+
|
149 |
+
</script>
|
150 |
+
|
151 |
+
<script type="text/template" id="tmpl-tawcvs-input-image">
|
152 |
+
|
153 |
+
<label><?php esc_html_e( 'Image', 'wcvs' ) ?></label><br>
|
154 |
+
<div class="tawcvs-term-image-thumbnail" style="float:left;margin-right:10px;">
|
155 |
+
<img src="<?php echo esc_url( WC()->plugin_url() . '/assets/images/placeholder.png' ) ?>" width="60px" height="60px" />
|
156 |
+
</div>
|
157 |
+
<div style="line-height:60px;">
|
158 |
+
<input type="hidden" class="tawcvs-input tawcvs-input-image tawcvs-term-image" name="swatch" value="" />
|
159 |
+
<button type="button" class="tawcvs-upload-image-button button"><?php esc_html_e( 'Upload/Add image', 'wcvs' ); ?></button>
|
160 |
+
<button type="button" class="tawcvs-remove-image-button button hidden"><?php esc_html_e( 'Remove image', 'wcvs' ); ?></button>
|
161 |
+
</div>
|
162 |
+
|
163 |
+
</script>
|
164 |
+
|
165 |
+
<script type="text/template" id="tmpl-tawcvs-input-label">
|
166 |
+
|
167 |
+
<label>
|
168 |
+
<?php esc_html_e( 'Label', 'wcvs' ) ?>
|
169 |
+
<input type="text" class="widefat tawcvs-input tawcvs-input-label" name="swatch">
|
170 |
+
</label>
|
171 |
+
|
172 |
+
</script>
|
173 |
+
|
174 |
+
<script type="text/template" id="tmpl-tawcvs-input-tax">
|
175 |
+
|
176 |
+
<input type="hidden" class="tawcvs-input" name="taxonomy" value="{{data.tax}}">
|
177 |
+
<input type="hidden" class="tawcvs-input" name="type" value="{{data.type}}">
|
178 |
+
|
179 |
+
</script>
|
180 |
+
<?php
|
181 |
+
}
|
182 |
+
}
|
183 |
+
|
184 |
+
new TA_WC_Variation_Swatches_Admin_Product();
|
includes/class-admin.php
CHANGED
@@ -1,390 +1,228 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Class TA_WC_Variation_Swatches_Admin
|
5 |
-
*/
|
6 |
-
class TA_WC_Variation_Swatches_Admin {
|
7 |
-
/**
|
8 |
-
* The single instance of the class
|
9 |
-
*
|
10 |
-
* @var TA_WC_Variation_Swatches_Admin
|
11 |
-
*/
|
12 |
-
protected static $instance = null;
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Main instance
|
16 |
-
*
|
17 |
-
* @return TA_WC_Variation_Swatches_Admin
|
18 |
-
*/
|
19 |
-
public static function instance() {
|
20 |
-
if ( null == self::$instance ) {
|
21 |
-
self::$instance = new self();
|
22 |
-
}
|
23 |
-
|
24 |
-
return self::$instance;
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Class constructor.
|
29 |
-
*/
|
30 |
-
public function __construct() {
|
31 |
-
add_action( 'admin_init', array( $this, '
|
32 |
-
add_action( '
|
33 |
-
add_action( '
|
34 |
-
|
35 |
-
// Display attribute fields
|
36 |
-
add_action( 'tawcvs_product_attribute_field', array( $this, 'attribute_fields' ), 10, 3 );
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
*
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
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 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
*
|
123 |
-
*
|
124 |
-
* @param $
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
'
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
<
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
*
|
173 |
-
*
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
*
|
187 |
-
*
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
$
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
return array_merge( $new_columns, $columns );
|
230 |
-
}
|
231 |
-
|
232 |
-
/**
|
233 |
-
* Render thumbnail HTML depend on attribute type
|
234 |
-
*
|
235 |
-
* @param $columns
|
236 |
-
* @param $column
|
237 |
-
* @param $term_id
|
238 |
-
*/
|
239 |
-
public function add_attribute_column_content( $columns, $column, $term_id ) {
|
240 |
-
$attr = TA_WCVS()->get_tax_attribute( $_REQUEST['taxonomy'] );
|
241 |
-
$value = get_term_meta( $term_id, $attr->attribute_type, true );
|
242 |
-
|
243 |
-
switch ( $attr->attribute_type ) {
|
244 |
-
case 'color':
|
245 |
-
printf( '<div class="swatch-preview swatch-color" style="background-color:%s;"></div>', esc_attr( $value ) );
|
246 |
-
break;
|
247 |
-
|
248 |
-
case 'image':
|
249 |
-
$image = $value ? wp_get_attachment_image_src( $value ) : '';
|
250 |
-
$image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png';
|
251 |
-
printf( '<img class="swatch-preview swatch-image" src="%s" width="44px" height="44px">', esc_url( $image ) );
|
252 |
-
break;
|
253 |
-
|
254 |
-
case 'label':
|
255 |
-
printf( '<div class="swatch-preview swatch-label">%s</div>', esc_html( $value ) );
|
256 |
-
break;
|
257 |
-
}
|
258 |
-
}
|
259 |
-
|
260 |
-
/**
|
261 |
-
* Print HTML of modal at admin footer and add js templates
|
262 |
-
*/
|
263 |
-
public function add_attribute_term_template() {
|
264 |
-
global $pagenow, $post;
|
265 |
-
|
266 |
-
if ( $pagenow != 'post.php' || ( isset( $post ) && get_post_type( $post->ID ) != 'product' ) ) {
|
267 |
-
return;
|
268 |
-
}
|
269 |
-
?>
|
270 |
-
|
271 |
-
<div id="tawcvs-modal-container" class="tawcvs-modal-container">
|
272 |
-
<div class="tawcvs-modal">
|
273 |
-
<button type="button" class="button-link media-modal-close tawcvs-modal-close">
|
274 |
-
<span class="media-modal-icon"></span></button>
|
275 |
-
<div class="tawcvs-modal-header"><h2><?php esc_html_e( 'Add new term', 'wcvs' ) ?></h2></div>
|
276 |
-
<div class="tawcvs-modal-content">
|
277 |
-
<p class="tawcvs-term-name">
|
278 |
-
<label>
|
279 |
-
<?php esc_html_e( 'Name', 'wcvs' ) ?>
|
280 |
-
<input type="text" class="widefat tawcvs-input" name="name">
|
281 |
-
</label>
|
282 |
-
</p>
|
283 |
-
<p class="tawcvs-term-slug">
|
284 |
-
<label>
|
285 |
-
<?php esc_html_e( 'Slug', 'wcvs' ) ?>
|
286 |
-
<input type="text" class="widefat tawcvs-input" name="slug">
|
287 |
-
</label>
|
288 |
-
</p>
|
289 |
-
<div class="tawcvs-term-swatch">
|
290 |
-
|
291 |
-
</div>
|
292 |
-
<div class="hidden tawcvs-term-tax"></div>
|
293 |
-
|
294 |
-
<input type="hidden" class="tawcvs-input" name="nonce" value="<?php echo wp_create_nonce( '_tawcvs_create_attribute' ) ?>">
|
295 |
-
</div>
|
296 |
-
<div class="tawcvs-modal-footer">
|
297 |
-
<button class="button button-secondary tawcvs-modal-close"><?php esc_html_e( 'Cancel', 'wcvs' ) ?></button>
|
298 |
-
<button class="button button-primary tawcvs-new-attribute-submit"><?php esc_html_e( 'Add New', 'wcvs' ) ?></button>
|
299 |
-
<span class="message"></span>
|
300 |
-
<span class="spinner"></span>
|
301 |
-
</div>
|
302 |
-
</div>
|
303 |
-
<div class="tawcvs-modal-backdrop media-modal-backdrop"></div>
|
304 |
-
</div>
|
305 |
-
|
306 |
-
<script type="text/template" id="tmpl-tawcvs-input-color">
|
307 |
-
|
308 |
-
<label><?php esc_html_e( 'Color', 'wcvs' ) ?></label><br>
|
309 |
-
<input type="text" class="tawcvs-input tawcvs-input-color" name="swatch">
|
310 |
-
|
311 |
-
</script>
|
312 |
-
|
313 |
-
<script type="text/template" id="tmpl-tawcvs-input-image">
|
314 |
-
|
315 |
-
<label><?php esc_html_e( 'Image', 'wcvs' ) ?></label><br>
|
316 |
-
<div class="tawcvs-term-image-thumbnail" style="float:left;margin-right:10px;">
|
317 |
-
<img src="<?php echo esc_url( WC()->plugin_url() . '/assets/images/placeholder.png' ) ?>" width="60px" height="60px" />
|
318 |
-
</div>
|
319 |
-
<div style="line-height:60px;">
|
320 |
-
<input type="hidden" class="tawcvs-input tawcvs-input-image tawcvs-term-image" name="swatch" value="" />
|
321 |
-
<button type="button" class="tawcvs-upload-image-button button"><?php esc_html_e( 'Upload/Add image', 'wcvs' ); ?></button>
|
322 |
-
<button type="button" class="tawcvs-remove-image-button button hidden"><?php esc_html_e( 'Remove image', 'wcvs' ); ?></button>
|
323 |
-
</div>
|
324 |
-
|
325 |
-
</script>
|
326 |
-
|
327 |
-
<script type="text/template" id="tmpl-tawcvs-input-label">
|
328 |
-
|
329 |
-
<label>
|
330 |
-
<?php esc_html_e( 'Label', 'wcvs' ) ?>
|
331 |
-
<input type="text" class="widefat tawcvs-input tawcvs-input-label" name="swatch">
|
332 |
-
</label>
|
333 |
-
|
334 |
-
</script>
|
335 |
-
|
336 |
-
<script type="text/template" id="tmpl-tawcvs-input-tax">
|
337 |
-
|
338 |
-
<input type="hidden" class="tawcvs-input" name="taxonomy" value="{{data.tax}}">
|
339 |
-
<input type="hidden" class="tawcvs-input" name="type" value="{{data.type}}">
|
340 |
-
|
341 |
-
</script>
|
342 |
-
<?php
|
343 |
-
}
|
344 |
-
|
345 |
-
/**
|
346 |
-
* Ajax function to handle add new attribute term
|
347 |
-
*/
|
348 |
-
public function add_new_attribute_ajax() {
|
349 |
-
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
350 |
-
$tax = isset( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : '';
|
351 |
-
$type = isset( $_POST['type'] ) ? $_POST['type'] : '';
|
352 |
-
$name = isset( $_POST['name'] ) ? $_POST['name'] : '';
|
353 |
-
$slug = isset( $_POST['slug'] ) ? $_POST['slug'] : '';
|
354 |
-
$swatch = isset( $_POST['swatch'] ) ? $_POST['swatch'] : '';
|
355 |
-
|
356 |
-
if ( ! wp_verify_nonce( $nonce, '_tawcvs_create_attribute' ) ) {
|
357 |
-
wp_send_json_error( esc_html__( 'Wrong request', 'wcvs' ) );
|
358 |
-
}
|
359 |
-
|
360 |
-
if ( empty( $name ) || empty( $swatch ) || empty( $tax ) || empty( $type ) ) {
|
361 |
-
wp_send_json_error( esc_html__( 'Not enough data', 'wcvs' ) );
|
362 |
-
}
|
363 |
-
|
364 |
-
if ( ! taxonomy_exists( $tax ) ) {
|
365 |
-
wp_send_json_error( esc_html__( 'Taxonomy is not exists', 'wcvs' ) );
|
366 |
-
}
|
367 |
-
|
368 |
-
if ( term_exists( $_POST['name'], $_POST['tax'] ) ) {
|
369 |
-
wp_send_json_error( esc_html__( 'This term is exists', 'wcvs' ) );
|
370 |
-
}
|
371 |
-
|
372 |
-
$term = wp_insert_term( $name, $tax, array( 'slug' => $slug ) );
|
373 |
-
|
374 |
-
if ( is_wp_error( $term ) ) {
|
375 |
-
wp_send_json_error( $term->get_error_message() );
|
376 |
-
} else {
|
377 |
-
$term = get_term_by( 'id', $term['term_id'], $tax );
|
378 |
-
update_term_meta( $term->term_id, $type, $swatch );
|
379 |
-
}
|
380 |
-
|
381 |
-
wp_send_json_success(
|
382 |
-
array(
|
383 |
-
'msg' => esc_html__( 'Added successfully', 'wcvs' ),
|
384 |
-
'id' => $term->term_id,
|
385 |
-
'slug' => $term->slug,
|
386 |
-
'name' => $term->name,
|
387 |
-
)
|
388 |
-
);
|
389 |
-
}
|
390 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class TA_WC_Variation_Swatches_Admin
|
5 |
+
*/
|
6 |
+
class TA_WC_Variation_Swatches_Admin {
|
7 |
+
/**
|
8 |
+
* The single instance of the class
|
9 |
+
*
|
10 |
+
* @var TA_WC_Variation_Swatches_Admin
|
11 |
+
*/
|
12 |
+
protected static $instance = null;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Main instance
|
16 |
+
*
|
17 |
+
* @return TA_WC_Variation_Swatches_Admin
|
18 |
+
*/
|
19 |
+
public static function instance() {
|
20 |
+
if ( null == self::$instance ) {
|
21 |
+
self::$instance = new self();
|
22 |
+
}
|
23 |
+
|
24 |
+
return self::$instance;
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Class constructor.
|
29 |
+
*/
|
30 |
+
public function __construct() {
|
31 |
+
add_action( 'admin_init', array( $this, 'includes' ) );
|
32 |
+
add_action( 'admin_init', array( $this, 'init_attribute_hooks' ) );
|
33 |
+
add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
|
34 |
+
|
35 |
+
// Display attribute fields
|
36 |
+
add_action( 'tawcvs_product_attribute_field', array( $this, 'attribute_fields' ), 10, 3 );
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Include any classes we need within admin.
|
41 |
+
*/
|
42 |
+
public function includes() {
|
43 |
+
include_once( dirname( __FILE__ ) . '/class-admin-product.php' );
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Init hooks for adding fields to attribute screen
|
48 |
+
* Save new term meta
|
49 |
+
* Add thumbnail column for attribute term
|
50 |
+
*/
|
51 |
+
public function init_attribute_hooks() {
|
52 |
+
$attribute_taxonomies = wc_get_attribute_taxonomies();
|
53 |
+
|
54 |
+
if ( empty( $attribute_taxonomies ) ) {
|
55 |
+
return;
|
56 |
+
}
|
57 |
+
|
58 |
+
foreach ( $attribute_taxonomies as $tax ) {
|
59 |
+
add_action( 'pa_' . $tax->attribute_name . '_add_form_fields', array( $this, 'add_attribute_fields' ) );
|
60 |
+
add_action( 'pa_' . $tax->attribute_name . '_edit_form_fields', array( $this, 'edit_attribute_fields' ), 10, 2 );
|
61 |
+
|
62 |
+
add_filter( 'manage_edit-pa_' . $tax->attribute_name . '_columns', array( $this, 'add_attribute_columns' ) );
|
63 |
+
add_filter( 'manage_pa_' . $tax->attribute_name . '_custom_column', array( $this, 'add_attribute_column_content' ), 10, 3 );
|
64 |
+
}
|
65 |
+
|
66 |
+
add_action( 'created_term', array( $this, 'save_term_meta' ), 10, 2 );
|
67 |
+
add_action( 'edit_term', array( $this, 'save_term_meta' ), 10, 2 );
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Load stylesheet and scripts in edit product attribute screen
|
72 |
+
*/
|
73 |
+
public function enqueue_scripts() {
|
74 |
+
$screen = get_current_screen();
|
75 |
+
if ( strpos( $screen->id, 'edit-pa_' ) === false && strpos( $screen->id, 'product' ) === false ) {
|
76 |
+
return;
|
77 |
+
}
|
78 |
+
|
79 |
+
wp_enqueue_media();
|
80 |
+
|
81 |
+
wp_enqueue_style( 'tawcvs-admin', plugins_url( '/assets/css/admin.css', dirname( __FILE__ ) ), array( 'wp-color-picker' ), '20160615' );
|
82 |
+
wp_enqueue_script( 'tawcvs-admin', plugins_url( '/assets/js/admin.js', dirname( __FILE__ ) ), array( 'jquery', 'wp-color-picker', 'wp-util' ), '20170113', true );
|
83 |
+
|
84 |
+
wp_localize_script(
|
85 |
+
'tawcvs-admin',
|
86 |
+
'tawcvs',
|
87 |
+
array(
|
88 |
+
'i18n' => array(
|
89 |
+
'mediaTitle' => esc_html__( 'Choose an image', 'wcvs' ),
|
90 |
+
'mediaButton' => esc_html__( 'Use image', 'wcvs' ),
|
91 |
+
),
|
92 |
+
'placeholder' => WC()->plugin_url() . '/assets/images/placeholder.png'
|
93 |
+
)
|
94 |
+
);
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Create hook to add fields to add attribute term screen
|
99 |
+
*
|
100 |
+
* @param string $taxonomy
|
101 |
+
*/
|
102 |
+
public function add_attribute_fields( $taxonomy ) {
|
103 |
+
$attr = TA_WCVS()->get_tax_attribute( $taxonomy );
|
104 |
+
|
105 |
+
do_action( 'tawcvs_product_attribute_field', $attr->attribute_type, '', 'add' );
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Create hook to fields to edit attribute term screen
|
110 |
+
*
|
111 |
+
* @param object $term
|
112 |
+
* @param string $taxonomy
|
113 |
+
*/
|
114 |
+
public function edit_attribute_fields( $term, $taxonomy ) {
|
115 |
+
$attr = TA_WCVS()->get_tax_attribute( $taxonomy );
|
116 |
+
$value = get_term_meta( $term->term_id, $attr->attribute_type, true );
|
117 |
+
|
118 |
+
do_action( 'tawcvs_product_attribute_field', $attr->attribute_type, $value, 'edit' );
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Print HTML of custom fields on attribute term screens
|
123 |
+
*
|
124 |
+
* @param $type
|
125 |
+
* @param $value
|
126 |
+
* @param $form
|
127 |
+
*/
|
128 |
+
public function attribute_fields( $type, $value, $form ) {
|
129 |
+
// Return if this is a default attribute type
|
130 |
+
if ( in_array( $type, array( 'select', 'text' ) ) ) {
|
131 |
+
return;
|
132 |
+
}
|
133 |
+
|
134 |
+
// Print the open tag of field container
|
135 |
+
printf(
|
136 |
+
'<%s class="form-field">%s<label for="term-%s">%s</label>%s',
|
137 |
+
'edit' == $form ? 'tr' : 'div',
|
138 |
+
'edit' == $form ? '<th>' : '',
|
139 |
+
esc_attr( $type ),
|
140 |
+
TA_WCVS()->types[$type],
|
141 |
+
'edit' == $form ? '</th><td>' : ''
|
142 |
+
);
|
143 |
+
|
144 |
+
switch ( $type ) {
|
145 |
+
case 'image':
|
146 |
+
$image = $value ? wp_get_attachment_image_src( $value ) : '';
|
147 |
+
$image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png';
|
148 |
+
?>
|
149 |
+
<div class="tawcvs-term-image-thumbnail" style="float:left;margin-right:10px;">
|
150 |
+
<img src="<?php echo esc_url( $image ) ?>" width="60px" height="60px" />
|
151 |
+
</div>
|
152 |
+
<div style="line-height:60px;">
|
153 |
+
<input type="hidden" class="tawcvs-term-image" name="image" value="<?php echo esc_attr( $value ) ?>" />
|
154 |
+
<button type="button" class="tawcvs-upload-image-button button"><?php esc_html_e( 'Upload/Add image', 'wcvs' ); ?></button>
|
155 |
+
<button type="button" class="tawcvs-remove-image-button button <?php echo $value ? '' : 'hidden' ?>"><?php esc_html_e( 'Remove image', 'wcvs' ); ?></button>
|
156 |
+
</div>
|
157 |
+
<?php
|
158 |
+
break;
|
159 |
+
|
160 |
+
default:
|
161 |
+
?>
|
162 |
+
<input type="text" id="term-<?php echo esc_attr( $type ) ?>" name="<?php echo esc_attr( $type ) ?>" value="<?php echo esc_attr( $value ) ?>" />
|
163 |
+
<?php
|
164 |
+
break;
|
165 |
+
}
|
166 |
+
|
167 |
+
// Print the close tag of field container
|
168 |
+
echo 'edit' == $form ? '</td></tr>' : '</div>';
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Save term meta
|
173 |
+
*
|
174 |
+
* @param int $term_id
|
175 |
+
* @param int $tt_id
|
176 |
+
*/
|
177 |
+
public function save_term_meta( $term_id, $tt_id ) {
|
178 |
+
foreach ( TA_WCVS()->types as $type => $label ) {
|
179 |
+
if ( isset( $_POST[$type] ) ) {
|
180 |
+
update_term_meta( $term_id, $type, $_POST[$type] );
|
181 |
+
}
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Add thumbnail column to column list
|
187 |
+
*
|
188 |
+
* @param array $columns
|
189 |
+
*
|
190 |
+
* @return array
|
191 |
+
*/
|
192 |
+
public function add_attribute_columns( $columns ) {
|
193 |
+
$new_columns = array();
|
194 |
+
$new_columns['cb'] = $columns['cb'];
|
195 |
+
$new_columns['thumb'] = '';
|
196 |
+
unset( $columns['cb'] );
|
197 |
+
|
198 |
+
return array_merge( $new_columns, $columns );
|
199 |
+
}
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Render thumbnail HTML depend on attribute type
|
203 |
+
*
|
204 |
+
* @param $columns
|
205 |
+
* @param $column
|
206 |
+
* @param $term_id
|
207 |
+
*/
|
208 |
+
public function add_attribute_column_content( $columns, $column, $term_id ) {
|
209 |
+
$attr = TA_WCVS()->get_tax_attribute( $_REQUEST['taxonomy'] );
|
210 |
+
$value = get_term_meta( $term_id, $attr->attribute_type, true );
|
211 |
+
|
212 |
+
switch ( $attr->attribute_type ) {
|
213 |
+
case 'color':
|
214 |
+
printf( '<div class="swatch-preview swatch-color" style="background-color:%s;"></div>', esc_attr( $value ) );
|
215 |
+
break;
|
216 |
+
|
217 |
+
case 'image':
|
218 |
+
$image = $value ? wp_get_attachment_image_src( $value ) : '';
|
219 |
+
$image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png';
|
220 |
+
printf( '<img class="swatch-preview swatch-image" src="%s" width="44px" height="44px">', esc_url( $image ) );
|
221 |
+
break;
|
222 |
+
|
223 |
+
case 'label':
|
224 |
+
printf( '<div class="swatch-preview swatch-label">%s</div>', esc_html( $value ) );
|
225 |
+
break;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-frontend.php
CHANGED
@@ -1,162 +1,162 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Class TA_WC_Variation_Swatches_Frontend
|
5 |
-
*/
|
6 |
-
class TA_WC_Variation_Swatches_Frontend {
|
7 |
-
/**
|
8 |
-
* The single instance of the class
|
9 |
-
*
|
10 |
-
* @var TA_WC_Variation_Swatches_Frontend
|
11 |
-
*/
|
12 |
-
protected static $instance = null;
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Main instance
|
16 |
-
*
|
17 |
-
* @return TA_WC_Variation_Swatches_Frontend
|
18 |
-
*/
|
19 |
-
public static function instance() {
|
20 |
-
if ( null == self::$instance ) {
|
21 |
-
self::$instance = new self();
|
22 |
-
}
|
23 |
-
|
24 |
-
return self::$instance;
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Class constructor.
|
29 |
-
*/
|
30 |
-
public function __construct() {
|
31 |
-
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
32 |
-
|
33 |
-
add_filter( 'woocommerce_dropdown_variation_attribute_options_html', array( $this, 'get_swatch_html' ), 100, 2 );
|
34 |
-
add_filter( 'tawcvs_swatch_html', array( $this, 'swatch_html' ), 5, 4 );
|
35 |
-
}
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Enqueue scripts and stylesheets
|
39 |
-
*/
|
40 |
-
public function enqueue_scripts() {
|
41 |
-
wp_enqueue_style( 'tawcvs-frontend', plugins_url( 'assets/css/frontend.css', dirname( __FILE__ ) ), array(), '20160615' );
|
42 |
-
wp_enqueue_script( 'tawcvs-frontend', plugins_url( 'assets/js/frontend.js', dirname( __FILE__ ) ), array( 'jquery' ), '20160615', true );
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Filter function to add swatches bellow the default selector
|
47 |
-
*
|
48 |
-
* @param $html
|
49 |
-
* @param $args
|
50 |
-
*
|
51 |
-
* @return string
|
52 |
-
*/
|
53 |
-
public function get_swatch_html( $html, $args ) {
|
54 |
-
$swatch_types = TA_WCVS()->types;
|
55 |
-
$attr = TA_WCVS()->get_tax_attribute( $args['attribute'] );
|
56 |
-
|
57 |
-
// Return if this is normal attribute
|
58 |
-
if ( empty( $attr ) ) {
|
59 |
-
return $html;
|
60 |
-
}
|
61 |
-
|
62 |
-
if ( ! array_key_exists( $attr->attribute_type, $swatch_types ) ) {
|
63 |
-
return $html;
|
64 |
-
}
|
65 |
-
|
66 |
-
$options = $args['options'];
|
67 |
-
$product = $args['product'];
|
68 |
-
$attribute = $args['attribute'];
|
69 |
-
$class = "variation-selector variation-select-{$attr->attribute_type}";
|
70 |
-
$swatches = '';
|
71 |
-
|
72 |
-
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
|
73 |
-
$attributes = $product->get_variation_attributes();
|
74 |
-
$options = $attributes[$attribute];
|
75 |
-
}
|
76 |
-
|
77 |
-
if ( array_key_exists( $attr->attribute_type, $swatch_types ) ) {
|
78 |
-
if ( ! empty( $options ) && $product && taxonomy_exists( $attribute ) ) {
|
79 |
-
// Get terms if this is a taxonomy - ordered. We need the names too.
|
80 |
-
$terms = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );
|
81 |
-
|
82 |
-
foreach ( $terms as $term ) {
|
83 |
-
if ( in_array( $term->slug, $options ) ) {
|
84 |
-
$swatches .= apply_filters( 'tawcvs_swatch_html', '', $term, $attr, $args );
|
85 |
-
}
|
86 |
-
}
|
87 |
-
}
|
88 |
-
|
89 |
-
if ( ! empty( $swatches ) ) {
|
90 |
-
$class .= ' hidden';
|
91 |
-
|
92 |
-
$swatches = '<div class="tawcvs-swatches" data-attribute_name="attribute_' . esc_attr( $attribute ) . '">' . $swatches . '</div>';
|
93 |
-
$html = '<div class="' . esc_attr( $class ) . '">' . $html . '</div>' . $swatches;
|
94 |
-
}
|
95 |
-
}
|
96 |
-
|
97 |
-
return $html;
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Print HTML of a single swatch
|
102 |
-
*
|
103 |
-
* @param $html
|
104 |
-
* @param $term
|
105 |
-
* @param $
|
106 |
-
* @param $args
|
107 |
-
*
|
108 |
-
* @return string
|
109 |
-
*/
|
110 |
-
public function swatch_html( $html, $term, $
|
111 |
-
$selected = sanitize_title( $args['selected'] ) == $term->slug ? 'selected' : '';
|
112 |
-
$name = esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) );
|
113 |
-
|
114 |
-
switch ( $
|
115 |
-
case 'color':
|
116 |
-
$color = get_term_meta( $term->term_id, 'color', true );
|
117 |
-
list( $r, $g, $b ) = sscanf( $color, "#%02x%02x%02x" );
|
118 |
-
$html = sprintf(
|
119 |
-
'<span class="swatch swatch-color swatch-%s %s" style="background-color:%s;color:%s;" title="%s" data-value="%s">%s</span>',
|
120 |
-
esc_attr( $term->slug ),
|
121 |
-
$selected,
|
122 |
-
esc_attr( $color ),
|
123 |
-
"rgba($r,$g,$b,0.5)",
|
124 |
-
esc_attr( $name ),
|
125 |
-
esc_attr( $term->slug ),
|
126 |
-
$name
|
127 |
-
);
|
128 |
-
break;
|
129 |
-
|
130 |
-
case 'image':
|
131 |
-
$image = get_term_meta( $term->term_id, 'image', true );
|
132 |
-
$image = $image ? wp_get_attachment_image_src( $image ) : '';
|
133 |
-
$image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png';
|
134 |
-
$html = sprintf(
|
135 |
-
'<span class="swatch swatch-image swatch-%s %s" title="%s" data-value="%s"><img src="%s" alt="%s">%s</span>',
|
136 |
-
esc_attr( $term->slug ),
|
137 |
-
$selected,
|
138 |
-
esc_attr( $name ),
|
139 |
-
esc_attr( $term->slug ),
|
140 |
-
esc_url( $image ),
|
141 |
-
esc_attr( $name ),
|
142 |
-
esc_attr( $name )
|
143 |
-
);
|
144 |
-
break;
|
145 |
-
|
146 |
-
case 'label':
|
147 |
-
$label = get_term_meta( $term->term_id, 'label', true );
|
148 |
-
$label = $label ? $label : $name;
|
149 |
-
$html = sprintf(
|
150 |
-
'<span class="swatch swatch-label swatch-%s %s" title="%s" data-value="%s">%s</span>',
|
151 |
-
esc_attr( $term->slug ),
|
152 |
-
$selected,
|
153 |
-
esc_attr( $name ),
|
154 |
-
esc_attr( $term->slug ),
|
155 |
-
esc_html( $label )
|
156 |
-
);
|
157 |
-
break;
|
158 |
-
}
|
159 |
-
|
160 |
-
return $html;
|
161 |
-
}
|
162 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class TA_WC_Variation_Swatches_Frontend
|
5 |
+
*/
|
6 |
+
class TA_WC_Variation_Swatches_Frontend {
|
7 |
+
/**
|
8 |
+
* The single instance of the class
|
9 |
+
*
|
10 |
+
* @var TA_WC_Variation_Swatches_Frontend
|
11 |
+
*/
|
12 |
+
protected static $instance = null;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Main instance
|
16 |
+
*
|
17 |
+
* @return TA_WC_Variation_Swatches_Frontend
|
18 |
+
*/
|
19 |
+
public static function instance() {
|
20 |
+
if ( null == self::$instance ) {
|
21 |
+
self::$instance = new self();
|
22 |
+
}
|
23 |
+
|
24 |
+
return self::$instance;
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Class constructor.
|
29 |
+
*/
|
30 |
+
public function __construct() {
|
31 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
32 |
+
|
33 |
+
add_filter( 'woocommerce_dropdown_variation_attribute_options_html', array( $this, 'get_swatch_html' ), 100, 2 );
|
34 |
+
add_filter( 'tawcvs_swatch_html', array( $this, 'swatch_html' ), 5, 4 );
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Enqueue scripts and stylesheets
|
39 |
+
*/
|
40 |
+
public function enqueue_scripts() {
|
41 |
+
wp_enqueue_style( 'tawcvs-frontend', plugins_url( 'assets/css/frontend.css', dirname( __FILE__ ) ), array(), '20160615' );
|
42 |
+
wp_enqueue_script( 'tawcvs-frontend', plugins_url( 'assets/js/frontend.js', dirname( __FILE__ ) ), array( 'jquery' ), '20160615', true );
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Filter function to add swatches bellow the default selector
|
47 |
+
*
|
48 |
+
* @param $html
|
49 |
+
* @param $args
|
50 |
+
*
|
51 |
+
* @return string
|
52 |
+
*/
|
53 |
+
public function get_swatch_html( $html, $args ) {
|
54 |
+
$swatch_types = TA_WCVS()->types;
|
55 |
+
$attr = TA_WCVS()->get_tax_attribute( $args['attribute'] );
|
56 |
+
|
57 |
+
// Return if this is normal attribute
|
58 |
+
if ( empty( $attr ) ) {
|
59 |
+
return $html;
|
60 |
+
}
|
61 |
+
|
62 |
+
if ( ! array_key_exists( $attr->attribute_type, $swatch_types ) ) {
|
63 |
+
return $html;
|
64 |
+
}
|
65 |
+
|
66 |
+
$options = $args['options'];
|
67 |
+
$product = $args['product'];
|
68 |
+
$attribute = $args['attribute'];
|
69 |
+
$class = "variation-selector variation-select-{$attr->attribute_type}";
|
70 |
+
$swatches = '';
|
71 |
+
|
72 |
+
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
|
73 |
+
$attributes = $product->get_variation_attributes();
|
74 |
+
$options = $attributes[$attribute];
|
75 |
+
}
|
76 |
+
|
77 |
+
if ( array_key_exists( $attr->attribute_type, $swatch_types ) ) {
|
78 |
+
if ( ! empty( $options ) && $product && taxonomy_exists( $attribute ) ) {
|
79 |
+
// Get terms if this is a taxonomy - ordered. We need the names too.
|
80 |
+
$terms = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );
|
81 |
+
|
82 |
+
foreach ( $terms as $term ) {
|
83 |
+
if ( in_array( $term->slug, $options ) ) {
|
84 |
+
$swatches .= apply_filters( 'tawcvs_swatch_html', '', $term, $attr->attribute_type, $args );
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
if ( ! empty( $swatches ) ) {
|
90 |
+
$class .= ' hidden';
|
91 |
+
|
92 |
+
$swatches = '<div class="tawcvs-swatches" data-attribute_name="attribute_' . esc_attr( $attribute ) . '">' . $swatches . '</div>';
|
93 |
+
$html = '<div class="' . esc_attr( $class ) . '">' . $html . '</div>' . $swatches;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
return $html;
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Print HTML of a single swatch
|
102 |
+
*
|
103 |
+
* @param $html
|
104 |
+
* @param $term
|
105 |
+
* @param $type
|
106 |
+
* @param $args
|
107 |
+
*
|
108 |
+
* @return string
|
109 |
+
*/
|
110 |
+
public function swatch_html( $html, $term, $type, $args ) {
|
111 |
+
$selected = sanitize_title( $args['selected'] ) == $term->slug ? 'selected' : '';
|
112 |
+
$name = esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) );
|
113 |
+
|
114 |
+
switch ( $type ) {
|
115 |
+
case 'color':
|
116 |
+
$color = get_term_meta( $term->term_id, 'color', true );
|
117 |
+
list( $r, $g, $b ) = sscanf( $color, "#%02x%02x%02x" );
|
118 |
+
$html = sprintf(
|
119 |
+
'<span class="swatch swatch-color swatch-%s %s" style="background-color:%s;color:%s;" title="%s" data-value="%s">%s</span>',
|
120 |
+
esc_attr( $term->slug ),
|
121 |
+
$selected,
|
122 |
+
esc_attr( $color ),
|
123 |
+
"rgba($r,$g,$b,0.5)",
|
124 |
+
esc_attr( $name ),
|
125 |
+
esc_attr( $term->slug ),
|
126 |
+
$name
|
127 |
+
);
|
128 |
+
break;
|
129 |
+
|
130 |
+
case 'image':
|
131 |
+
$image = get_term_meta( $term->term_id, 'image', true );
|
132 |
+
$image = $image ? wp_get_attachment_image_src( $image ) : '';
|
133 |
+
$image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png';
|
134 |
+
$html = sprintf(
|
135 |
+
'<span class="swatch swatch-image swatch-%s %s" title="%s" data-value="%s"><img src="%s" alt="%s">%s</span>',
|
136 |
+
esc_attr( $term->slug ),
|
137 |
+
$selected,
|
138 |
+
esc_attr( $name ),
|
139 |
+
esc_attr( $term->slug ),
|
140 |
+
esc_url( $image ),
|
141 |
+
esc_attr( $name ),
|
142 |
+
esc_attr( $name )
|
143 |
+
);
|
144 |
+
break;
|
145 |
+
|
146 |
+
case 'label':
|
147 |
+
$label = get_term_meta( $term->term_id, 'label', true );
|
148 |
+
$label = $label ? $label : $name;
|
149 |
+
$html = sprintf(
|
150 |
+
'<span class="swatch swatch-label swatch-%s %s" title="%s" data-value="%s">%s</span>',
|
151 |
+
esc_attr( $term->slug ),
|
152 |
+
$selected,
|
153 |
+
esc_attr( $name ),
|
154 |
+
esc_attr( $term->slug ),
|
155 |
+
esc_html( $label )
|
156 |
+
);
|
157 |
+
break;
|
158 |
+
}
|
159 |
+
|
160 |
+
return $html;
|
161 |
+
}
|
162 |
}
|
includes/class-variation-swatches.php
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* The main plugin class
|
5 |
+
*/
|
6 |
+
final class TA_WC_Variation_Swatches {
|
7 |
+
/**
|
8 |
+
* The single instance of the class
|
9 |
+
*
|
10 |
+
* @var TA_WC_Variation_Swatches
|
11 |
+
*/
|
12 |
+
protected static $instance = null;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Extra attribute types
|
16 |
+
*
|
17 |
+
* @var array
|
18 |
+
*/
|
19 |
+
public $types = array();
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Main instance
|
23 |
+
*
|
24 |
+
* @return TA_WC_Variation_Swatches
|
25 |
+
*/
|
26 |
+
public static function instance() {
|
27 |
+
if ( null == self::$instance ) {
|
28 |
+
self::$instance = new self();
|
29 |
+
}
|
30 |
+
|
31 |
+
return self::$instance;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Class constructor.
|
36 |
+
*/
|
37 |
+
public function __construct() {
|
38 |
+
$this->types = array(
|
39 |
+
'color' => esc_html__( 'Color', 'wcvs' ),
|
40 |
+
'image' => esc_html__( 'Image', 'wcvs' ),
|
41 |
+
'label' => esc_html__( 'Label', 'wcvs' ),
|
42 |
+
);
|
43 |
+
|
44 |
+
$this->includes();
|
45 |
+
$this->init_hooks();
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Include required core files used in admin and on the frontend.
|
50 |
+
*/
|
51 |
+
public function includes() {
|
52 |
+
require_once dirname( __FILE__ ) . '/class-frontend.php';
|
53 |
+
|
54 |
+
if ( is_admin() ) {
|
55 |
+
require_once dirname( __FILE__ ) . '/class-admin.php';
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Initialize hooks
|
61 |
+
*/
|
62 |
+
public function init_hooks() {
|
63 |
+
add_action( 'init', array( $this, 'load_textdomain' ) );
|
64 |
+
|
65 |
+
add_filter( 'product_attributes_type_selector', array( $this, 'add_attribute_types' ) );
|
66 |
+
|
67 |
+
if ( is_admin() ) {
|
68 |
+
add_action( 'init', array( 'TA_WC_Variation_Swatches_Admin', 'instance' ) );
|
69 |
+
}
|
70 |
+
|
71 |
+
if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
72 |
+
add_action( 'init', array( 'TA_WC_Variation_Swatches_Frontend', 'instance' ) );
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Load plugin text domain
|
78 |
+
*/
|
79 |
+
public function load_textdomain() {
|
80 |
+
load_plugin_textdomain( 'wcvs', false, dirname( plugin_basename( TAWC_VS_PLUGIN_FILE ) ) . '/languages/' );
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Add extra attribute types
|
85 |
+
* Add color, image and label type
|
86 |
+
*
|
87 |
+
* @param array $types
|
88 |
+
*
|
89 |
+
* @return array
|
90 |
+
*/
|
91 |
+
public function add_attribute_types( $types ) {
|
92 |
+
$types = array_merge( $types, $this->types );
|
93 |
+
|
94 |
+
return $types;
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Get attribute's properties
|
99 |
+
*
|
100 |
+
* @param string $taxonomy
|
101 |
+
*
|
102 |
+
* @return object
|
103 |
+
*/
|
104 |
+
public function get_tax_attribute( $taxonomy ) {
|
105 |
+
global $wpdb;
|
106 |
+
|
107 |
+
$attr = substr( $taxonomy, 3 );
|
108 |
+
$attr = $wpdb->get_row( "SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '$attr'" );
|
109 |
+
|
110 |
+
return $attr;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Instance of admin
|
115 |
+
*
|
116 |
+
* @return object
|
117 |
+
*/
|
118 |
+
public function admin() {
|
119 |
+
return TA_WC_Variation_Swatches_Admin::instance();
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Instance of frontend
|
124 |
+
*
|
125 |
+
* @return object
|
126 |
+
*/
|
127 |
+
public function frontend() {
|
128 |
+
return TA_WC_Variation_Swatches_Frontend::instance();
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
if ( ! function_exists( 'TA_WCVS' ) ) {
|
133 |
+
/**
|
134 |
+
* Main instance of plugin
|
135 |
+
*
|
136 |
+
* @return TA_WC_Variation_Swatches
|
137 |
+
*/
|
138 |
+
function TA_WCVS() {
|
139 |
+
return TA_WC_Variation_Swatches::instance();
|
140 |
+
}
|
141 |
+
}
|
languages/wcvs.pot
CHANGED
@@ -1,127 +1,127 @@
|
|
1 |
-
#, fuzzy
|
2 |
-
msgid ""
|
3 |
-
msgstr ""
|
4 |
-
"Project-Id-Version: PACKAGE VERSION\n"
|
5 |
-
"Report-Msgid-Bugs-To: \n"
|
6 |
-
"POT-Creation-Date: 2017-01-14 10:16+0000\n"
|
7 |
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
8 |
-
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
9 |
-
"Language-Team: \n"
|
10 |
-
"Language: \n"
|
11 |
-
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
12 |
-
"MIME-Version: 1.0\n"
|
13 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
14 |
-
"Content-Transfer-Encoding: 8bit\n"
|
15 |
-
"X-Generator: Loco https://localise.biz/"
|
16 |
-
|
17 |
-
#: woocommerce-variation-swatches.php:57 includes/class-admin.php:303
|
18 |
-
msgid "Color"
|
19 |
-
msgstr ""
|
20 |
-
|
21 |
-
#: woocommerce-variation-swatches.php:58 includes/class-admin.php:310
|
22 |
-
msgid "Image"
|
23 |
-
msgstr ""
|
24 |
-
|
25 |
-
#: woocommerce-variation-swatches.php:59 includes/class-admin.php:325
|
26 |
-
msgid "Label"
|
27 |
-
msgstr ""
|
28 |
-
|
29 |
-
#: woocommerce-variation-swatches.php:161
|
30 |
-
msgid ""
|
31 |
-
"Soo Product Attribute Swatches is enabled but not effective. It requires "
|
32 |
-
"WooCommerce in order to work."
|
33 |
-
msgstr ""
|
34 |
-
|
35 |
-
#: includes/class-admin.php:87
|
36 |
-
msgid "Choose an image"
|
37 |
-
msgstr ""
|
38 |
-
|
39 |
-
#: includes/class-admin.php:88
|
40 |
-
msgid "Use image"
|
41 |
-
msgstr ""
|
42 |
-
|
43 |
-
#: includes/class-admin.php:147 includes/class-admin.php:316
|
44 |
-
msgid "Upload/Add image"
|
45 |
-
msgstr ""
|
46 |
-
|
47 |
-
#: includes/class-admin.php:148 includes/class-admin.php:317
|
48 |
-
msgid "Remove image"
|
49 |
-
msgstr ""
|
50 |
-
|
51 |
-
#: includes/class-admin.php:193
|
52 |
-
msgid "Select terms"
|
53 |
-
msgstr ""
|
54 |
-
|
55 |
-
#: includes/class-admin.php:204
|
56 |
-
msgid "Select all"
|
57 |
-
msgstr ""
|
58 |
-
|
59 |
-
#: includes/class-admin.php:205
|
60 |
-
msgid "Select none"
|
61 |
-
msgstr ""
|
62 |
-
|
63 |
-
#: includes/class-admin.php:206
|
64 |
-
msgid "Add new"
|
65 |
-
msgstr ""
|
66 |
-
|
67 |
-
#: includes/class-admin.php:270
|
68 |
-
msgid "Add new term"
|
69 |
-
msgstr ""
|
70 |
-
|
71 |
-
#: includes/class-admin.php:274
|
72 |
-
msgid "Name"
|
73 |
-
msgstr ""
|
74 |
-
|
75 |
-
#: includes/class-admin.php:280
|
76 |
-
msgid "Slug"
|
77 |
-
msgstr ""
|
78 |
-
|
79 |
-
#: includes/class-admin.php:292
|
80 |
-
msgid "Cancel"
|
81 |
-
msgstr ""
|
82 |
-
|
83 |
-
#: includes/class-admin.php:293
|
84 |
-
msgid "Add New"
|
85 |
-
msgstr ""
|
86 |
-
|
87 |
-
#: includes/class-admin.php:352
|
88 |
-
msgid "Wrong request"
|
89 |
-
msgstr ""
|
90 |
-
|
91 |
-
#: includes/class-admin.php:356
|
92 |
-
msgid "Not enough data"
|
93 |
-
msgstr ""
|
94 |
-
|
95 |
-
#: includes/class-admin.php:360
|
96 |
-
msgid "Taxonomy is not exists"
|
97 |
-
msgstr ""
|
98 |
-
|
99 |
-
#: includes/class-admin.php:364
|
100 |
-
msgid "This term is exists"
|
101 |
-
msgstr ""
|
102 |
-
|
103 |
-
#: includes/class-admin.php:378
|
104 |
-
msgid "Added successfully"
|
105 |
-
msgstr ""
|
106 |
-
|
107 |
-
#. Name of the plugin
|
108 |
-
msgid "WooCommerce Variation Swatches"
|
109 |
-
msgstr ""
|
110 |
-
|
111 |
-
#. Description of the plugin
|
112 |
-
msgid ""
|
113 |
-
"An extension of WooCommerce to make variation products be more beauty and "
|
114 |
-
"friendly with users."
|
115 |
-
msgstr ""
|
116 |
-
|
117 |
-
#. URI of the plugin
|
118 |
-
msgid "http://themealien.com/wordpress-plugin/woocommerce-variation-swatches"
|
119 |
-
msgstr ""
|
120 |
-
|
121 |
-
#. Author of the plugin
|
122 |
-
msgid "ThemeAlien"
|
123 |
-
msgstr ""
|
124 |
-
|
125 |
-
#. Author URI of the plugin
|
126 |
-
msgid "http://themealien.com/"
|
127 |
-
msgstr ""
|
1 |
+
#, fuzzy
|
2 |
+
msgid ""
|
3 |
+
msgstr ""
|
4 |
+
"Project-Id-Version: PACKAGE VERSION\n"
|
5 |
+
"Report-Msgid-Bugs-To: \n"
|
6 |
+
"POT-Creation-Date: 2017-01-14 10:16+0000\n"
|
7 |
+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
8 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
9 |
+
"Language-Team: \n"
|
10 |
+
"Language: \n"
|
11 |
+
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
12 |
+
"MIME-Version: 1.0\n"
|
13 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
14 |
+
"Content-Transfer-Encoding: 8bit\n"
|
15 |
+
"X-Generator: Loco https://localise.biz/"
|
16 |
+
|
17 |
+
#: woocommerce-variation-swatches.php:57 includes/class-admin.php:303
|
18 |
+
msgid "Color"
|
19 |
+
msgstr ""
|
20 |
+
|
21 |
+
#: woocommerce-variation-swatches.php:58 includes/class-admin.php:310
|
22 |
+
msgid "Image"
|
23 |
+
msgstr ""
|
24 |
+
|
25 |
+
#: woocommerce-variation-swatches.php:59 includes/class-admin.php:325
|
26 |
+
msgid "Label"
|
27 |
+
msgstr ""
|
28 |
+
|
29 |
+
#: woocommerce-variation-swatches.php:161
|
30 |
+
msgid ""
|
31 |
+
"Soo Product Attribute Swatches is enabled but not effective. It requires "
|
32 |
+
"WooCommerce in order to work."
|
33 |
+
msgstr ""
|
34 |
+
|
35 |
+
#: includes/class-admin.php:87
|
36 |
+
msgid "Choose an image"
|
37 |
+
msgstr ""
|
38 |
+
|
39 |
+
#: includes/class-admin.php:88
|
40 |
+
msgid "Use image"
|
41 |
+
msgstr ""
|
42 |
+
|
43 |
+
#: includes/class-admin.php:147 includes/class-admin.php:316
|
44 |
+
msgid "Upload/Add image"
|
45 |
+
msgstr ""
|
46 |
+
|
47 |
+
#: includes/class-admin.php:148 includes/class-admin.php:317
|
48 |
+
msgid "Remove image"
|
49 |
+
msgstr ""
|
50 |
+
|
51 |
+
#: includes/class-admin.php:193
|
52 |
+
msgid "Select terms"
|
53 |
+
msgstr ""
|
54 |
+
|
55 |
+
#: includes/class-admin.php:204
|
56 |
+
msgid "Select all"
|
57 |
+
msgstr ""
|
58 |
+
|
59 |
+
#: includes/class-admin.php:205
|
60 |
+
msgid "Select none"
|
61 |
+
msgstr ""
|
62 |
+
|
63 |
+
#: includes/class-admin.php:206
|
64 |
+
msgid "Add new"
|
65 |
+
msgstr ""
|
66 |
+
|
67 |
+
#: includes/class-admin.php:270
|
68 |
+
msgid "Add new term"
|
69 |
+
msgstr ""
|
70 |
+
|
71 |
+
#: includes/class-admin.php:274
|
72 |
+
msgid "Name"
|
73 |
+
msgstr ""
|
74 |
+
|
75 |
+
#: includes/class-admin.php:280
|
76 |
+
msgid "Slug"
|
77 |
+
msgstr ""
|
78 |
+
|
79 |
+
#: includes/class-admin.php:292
|
80 |
+
msgid "Cancel"
|
81 |
+
msgstr ""
|
82 |
+
|
83 |
+
#: includes/class-admin.php:293
|
84 |
+
msgid "Add New"
|
85 |
+
msgstr ""
|
86 |
+
|
87 |
+
#: includes/class-admin.php:352
|
88 |
+
msgid "Wrong request"
|
89 |
+
msgstr ""
|
90 |
+
|
91 |
+
#: includes/class-admin.php:356
|
92 |
+
msgid "Not enough data"
|
93 |
+
msgstr ""
|
94 |
+
|
95 |
+
#: includes/class-admin.php:360
|
96 |
+
msgid "Taxonomy is not exists"
|
97 |
+
msgstr ""
|
98 |
+
|
99 |
+
#: includes/class-admin.php:364
|
100 |
+
msgid "This term is exists"
|
101 |
+
msgstr ""
|
102 |
+
|
103 |
+
#: includes/class-admin.php:378
|
104 |
+
msgid "Added successfully"
|
105 |
+
msgstr ""
|
106 |
+
|
107 |
+
#. Name of the plugin
|
108 |
+
msgid "WooCommerce Variation Swatches"
|
109 |
+
msgstr ""
|
110 |
+
|
111 |
+
#. Description of the plugin
|
112 |
+
msgid ""
|
113 |
+
"An extension of WooCommerce to make variation products be more beauty and "
|
114 |
+
"friendly with users."
|
115 |
+
msgstr ""
|
116 |
+
|
117 |
+
#. URI of the plugin
|
118 |
+
msgid "http://themealien.com/wordpress-plugin/woocommerce-variation-swatches"
|
119 |
+
msgstr ""
|
120 |
+
|
121 |
+
#. Author of the plugin
|
122 |
+
msgid "ThemeAlien"
|
123 |
+
msgstr ""
|
124 |
+
|
125 |
+
#. Author URI of the plugin
|
126 |
+
msgid "http://themealien.com/"
|
127 |
+
msgstr ""
|
readme.txt
CHANGED
@@ -1,89 +1,93 @@
|
|
1 |
-
=== Variation Swatches for WooCommerce ===
|
2 |
-
Contributors: themealien
|
3 |
-
Tags: woocommerce, product attribute, product color, product size, variation swatches, variable products
|
4 |
-
Requires at least: 4.5
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 1.0.
|
7 |
-
License: GPLv2 or later
|
8 |
-
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
9 |
-
|
10 |
-
An extension of WooCommerce that make variable products be more beauty and friendly
|
11 |
-
|
12 |
-
== Description ==
|
13 |
-
|
14 |
-
Variation Swatches for WooCommerce plugin provides a much nicer way to display variations of variable products. This plugin will help you select style for each attribute as color, image or label. With this plugin, you can present product colors, sizes, styles and
|
15 |
-
This plugin only
|
16 |
-
|
17 |
-
With a friendly and easy-to-use interface, you can add default color, image or label to each attribute in the
|
18 |
-
|
19 |
-
**Features provided with this plugin:**
|
20 |
-
|
21 |
-
* Completely integrate with WooCommerce plugin
|
22 |
-
* Work on variable product only
|
23 |
-
* Create attribute color swatches
|
24 |
-
* Create attribute image swatches
|
25 |
-
* Create attribute label/text swatches
|
26 |
-
* Manage attribute globally
|
27 |
-
* Create new attribute swatch in product editing page
|
28 |
-
* New options in WooCommerce Settings that help control swatches easier without touching code
|
29 |
-
|
30 |
-
|
31 |
-
== Installation ==
|
32 |
-
|
33 |
-
= Automatic installation =
|
34 |
-
|
35 |
-
Automatic installation is the easiest option as WordPress handles the file transfers itself and you don’t need to leave your web browser.
|
36 |
-
|
37 |
-
1. Log in to your WordPress dashboard, navigate to the Plugins menu and click Add New.
|
38 |
-
1. In the search field type "Variation Swatches for WooCommerce" and click Search Plugins.
|
39 |
-
1. Once you’ve found it, you can install it by simply clicking Install Now button.
|
40 |
-
|
41 |
-
= Manual Installation =
|
42 |
-
|
43 |
-
1. Download the Variation Swatches for WooCommerce plugin to your desktop.
|
44 |
-
1. Extract the plugin folder to your desktop.
|
45 |
-
1. Read through the "readme" file thoroughly to ensure you follow the installation instructions.
|
46 |
-
1. With your FTP program, upload the Plugin folder to the wp-content/plugins folder in your WordPress directory online.
|
47 |
-
1. Go to Plugins screen and find the "Variation Swatches for WooCommerce" in the list.
|
48 |
-
1. Click Activate to activate it.
|
49 |
-
|
50 |
-
= Config attributes =
|
51 |
-
|
52 |
-
Even this plugin has been installed and activated on your site, variable products will still show dropdowns if you've not configured product attributes.
|
53 |
-
|
54 |
-
1. Log in to your WordPress dashboard, navigate to the Products menu and click Attributes.
|
55 |
-
1. Click to attribute name to edit an exists attribute or in the Add New Attribute form you will see the default Type selector.
|
56 |
-
1. Click to that Type selector to change attribute's type. Besides default options Select and Text, there are more 3 options Color, Image, Label to choose.
|
57 |
-
1. Select the suitable type for your attribute and click Save Change/Add attribute
|
58 |
-
1. Go back to manage attributes screen. Click the cog icon on the right side of attribute to start editing terms.
|
59 |
-
1. Start adding new terms or editing exists terms. There is will be a new option at the end of form that let you choose the color, upload image or type the label for those terms.
|
60 |
-
|
61 |
-
|
62 |
-
== Frequently Asked Questions ==
|
63 |
-
|
64 |
-
= Will this plugin work with my theme? =
|
65 |
-
Yes, it will work with any theme, but may require some styling to make it match nicely.
|
66 |
-
|
67 |
-
== Screenshots ==
|
68 |
-
|
69 |
-
1. Variations on frontend
|
70 |
-
1. Add new attribute
|
71 |
-
1. Edit Attribute
|
72 |
-
1. Attribute color
|
73 |
-
1. Attribute label
|
74 |
-
1. Attribute image
|
75 |
-
1. Add new attribute color when edit a product
|
76 |
-
|
77 |
-
== Changelog ==
|
78 |
-
|
79 |
-
= 1.0.
|
80 |
-
* Fix the issue of
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
89 |
* Initial release.
|
1 |
+
=== Variation Swatches for WooCommerce ===
|
2 |
+
Contributors: themealien
|
3 |
+
Tags: woocommerce, product attribute, product color, product size, variation swatches, variable products
|
4 |
+
Requires at least: 4.5
|
5 |
+
Tested up to: 5.0
|
6 |
+
Stable tag: 1.0.4
|
7 |
+
License: GPLv2 or later
|
8 |
+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
|
10 |
+
An extension of WooCommerce that make variable products be more beauty and friendly to customers.
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
Variation Swatches for WooCommerce plugin provides a much nicer way to display variations of variable products. This plugin will help you select style for each attribute as color, image or label. With this plugin, you can present product colors, sizes, styles and many things in a better way which is not supported by WooCommerce.
|
15 |
+
This plugin only adds more options to show product variations with swatches. It doesn't touch the default drop-down style of WooCommerce.
|
16 |
+
|
17 |
+
With a friendly and easy-to-use interface, you can add default color, image or label to each attribute in the attributes management page. It can also helps you pick the right style for quick-add attribute right inside the editing product page.
|
18 |
+
|
19 |
+
**Features provided with this plugin:**
|
20 |
+
|
21 |
+
* Completely integrate with WooCommerce plugin
|
22 |
+
* Work on variable product only
|
23 |
+
* Create attribute color swatches
|
24 |
+
* Create attribute image swatches
|
25 |
+
* Create attribute label/text swatches
|
26 |
+
* Manage attribute globally
|
27 |
+
* Create new attribute swatch in product editing page
|
28 |
+
* New options in WooCommerce Settings that help control swatches easier without touching code
|
29 |
+
|
30 |
+
|
31 |
+
== Installation ==
|
32 |
+
|
33 |
+
= Automatic installation =
|
34 |
+
|
35 |
+
Automatic installation is the easiest option as WordPress handles the file transfers itself and you don’t need to leave your web browser.
|
36 |
+
|
37 |
+
1. Log in to your WordPress dashboard, navigate to the Plugins menu and click Add New.
|
38 |
+
1. In the search field type "Variation Swatches for WooCommerce" and click Search Plugins.
|
39 |
+
1. Once you’ve found it, you can install it by simply clicking Install Now button.
|
40 |
+
|
41 |
+
= Manual Installation =
|
42 |
+
|
43 |
+
1. Download the Variation Swatches for WooCommerce plugin to your desktop.
|
44 |
+
1. Extract the plugin folder to your desktop.
|
45 |
+
1. Read through the "readme" file thoroughly to ensure you follow the installation instructions.
|
46 |
+
1. With your FTP program, upload the Plugin folder to the wp-content/plugins folder in your WordPress directory online.
|
47 |
+
1. Go to Plugins screen and find the "Variation Swatches for WooCommerce" in the list.
|
48 |
+
1. Click Activate to activate it.
|
49 |
+
|
50 |
+
= Config attributes =
|
51 |
+
|
52 |
+
Even this plugin has been installed and activated on your site, variable products will still show dropdowns if you've not configured product attributes.
|
53 |
+
|
54 |
+
1. Log in to your WordPress dashboard, navigate to the Products menu and click Attributes.
|
55 |
+
1. Click to attribute name to edit an exists attribute or in the Add New Attribute form you will see the default Type selector.
|
56 |
+
1. Click to that Type selector to change attribute's type. Besides default options Select and Text, there are more 3 options Color, Image, Label to choose.
|
57 |
+
1. Select the suitable type for your attribute and click Save Change/Add attribute
|
58 |
+
1. Go back to manage attributes screen. Click the cog icon on the right side of attribute to start editing terms.
|
59 |
+
1. Start adding new terms or editing exists terms. There is will be a new option at the end of form that let you choose the color, upload image or type the label for those terms.
|
60 |
+
|
61 |
+
|
62 |
+
== Frequently Asked Questions ==
|
63 |
+
|
64 |
+
= Will this plugin work with my theme? =
|
65 |
+
Yes, it will work with any theme, but may require some styling to make it match nicely.
|
66 |
+
|
67 |
+
== Screenshots ==
|
68 |
+
|
69 |
+
1. Variations on frontend
|
70 |
+
1. Add new attribute
|
71 |
+
1. Edit Attribute
|
72 |
+
1. Attribute color
|
73 |
+
1. Attribute label
|
74 |
+
1. Attribute image
|
75 |
+
1. Add new attribute color when edit a product
|
76 |
+
|
77 |
+
== Changelog ==
|
78 |
+
|
79 |
+
= 1.0.4 =
|
80 |
+
* Fix the issue of product attributes are not saved.
|
81 |
+
* Restore attribute type to "Select" if the plugin is deactivated.
|
82 |
+
|
83 |
+
= 1.0.3 =
|
84 |
+
* Fix the issue of adding attributes in the "Attributes" tab
|
85 |
+
|
86 |
+
= 1.0.2 =
|
87 |
+
* Support WooCommerce 3.0
|
88 |
+
|
89 |
+
= 1.0.1 =
|
90 |
+
* Add "swatches-support" class to the variations form
|
91 |
+
|
92 |
+
= 1.0.0 =
|
93 |
* Initial release.
|
uninstall.php
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Uninstall plugin
|
4 |
-
*/
|
5 |
-
|
6 |
-
// If uninstall not called from WordPress exit
|
7 |
-
if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
8 |
-
exit;
|
9 |
-
}
|
10 |
-
|
11 |
-
global $wpdb;
|
12 |
-
|
13 |
-
//change to standard select type custom attributes
|
14 |
-
$table = $wpdb->prefix . 'woocommerce_attribute_taxonomies';
|
15 |
-
$update = "UPDATE `$table` SET `attribute_type` = 'select' WHERE `attribute_type` != 'text'";
|
16 |
$wpdb->query( $update );
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Uninstall plugin
|
4 |
+
*/
|
5 |
+
|
6 |
+
// If uninstall not called from WordPress exit
|
7 |
+
if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
8 |
+
exit;
|
9 |
+
}
|
10 |
+
|
11 |
+
global $wpdb;
|
12 |
+
|
13 |
+
//change to standard select type custom attributes
|
14 |
+
$table = $wpdb->prefix . 'woocommerce_attribute_taxonomies';
|
15 |
+
$update = "UPDATE `$table` SET `attribute_type` = 'select' WHERE `attribute_type` != 'text'";
|
16 |
$wpdb->query( $update );
|
variation-swatches-for-woocommerce.php
CHANGED
@@ -1,181 +1,145 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Plugin Name: WooCommerce Variation Swatches
|
4 |
-
* Plugin URI: http://themealien.com/wordpress-plugin/woocommerce-variation-swatches
|
5 |
-
* Description: An extension of WooCommerce to make variable products be more beauty and friendly
|
6 |
-
* Version: 1.0.
|
7 |
-
* Author: ThemeAlien
|
8 |
-
* Author URI: http://themealien.com/
|
9 |
-
* Requires at least: 4.5
|
10 |
-
* Tested up to:
|
11 |
-
* License: GPLv2 or later
|
12 |
-
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
13 |
-
* Text Domain:
|
14 |
-
* Domain Path: /languages/
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
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 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
* Main instance of plugin
|
147 |
-
*
|
148 |
-
* @return TA_WC_Variation_Swatches
|
149 |
-
*/
|
150 |
-
function TA_WCVS() {
|
151 |
-
return TA_WC_Variation_Swatches::instance();
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* Display notice in case of WooCommerce plugin is not activated
|
156 |
-
*/
|
157 |
-
function ta_wc_variation_swatches_wc_notice() {
|
158 |
-
?>
|
159 |
-
|
160 |
-
<div class="error">
|
161 |
-
<p><?php esc_html_e( 'Soo Product Attribute Swatches is enabled but not effective. It requires WooCommerce in order to work.', 'wcvs' ); ?></p>
|
162 |
-
</div>
|
163 |
-
|
164 |
-
<?php
|
165 |
-
}
|
166 |
-
|
167 |
-
/**
|
168 |
-
* Construct plugin when plugins loaded in order to make sure WooCommerce API is fully loaded
|
169 |
-
* Check if WooCommerce is not activated then show an admin notice
|
170 |
-
* or create the main instance of plugin
|
171 |
-
*/
|
172 |
-
function ta_wc_variation_swatches_constructor() {
|
173 |
-
if ( ! function_exists( 'WC' ) ) {
|
174 |
-
add_action( 'admin_notices', 'ta_wc_variation_swatches_wc_notice' );
|
175 |
-
} else {
|
176 |
-
TA_WCVS();
|
177 |
-
}
|
178 |
-
}
|
179 |
-
|
180 |
-
add_action( 'plugins_loaded', 'ta_wc_variation_swatches_constructor' );
|
181 |
-
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: WooCommerce Variation Swatches
|
4 |
+
* Plugin URI: http://themealien.com/wordpress-plugin/woocommerce-variation-swatches
|
5 |
+
* Description: An extension of WooCommerce to make variable products be more beauty and friendly to users.
|
6 |
+
* Version: 1.0.4
|
7 |
+
* Author: ThemeAlien
|
8 |
+
* Author URI: http://themealien.com/
|
9 |
+
* Requires at least: 4.5
|
10 |
+
* Tested up to: 5.0
|
11 |
+
* License: GPLv2 or later
|
12 |
+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
13 |
+
* Text Domain: wcvs
|
14 |
+
* Domain Path: /languages/
|
15 |
+
* WC requires at least: 3.0.0
|
16 |
+
* WC tested up to: 3.5.1
|
17 |
+
*/
|
18 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
19 |
+
exit; // Exit if accessed directly.
|
20 |
+
}
|
21 |
+
|
22 |
+
// Define TAWC_DEALS_PLUGIN_FILE
|
23 |
+
if ( ! defined( 'TAWC_VS_PLUGIN_FILE' ) ) {
|
24 |
+
define( 'TAWC_VS_PLUGIN_FILE', __FILE__ );
|
25 |
+
}
|
26 |
+
|
27 |
+
if ( ! function_exists( 'ta_wc_variation_swatches_wc_notice' ) ) {
|
28 |
+
/**
|
29 |
+
* Display notice in case of WooCommerce plugin is not activated
|
30 |
+
*/
|
31 |
+
function ta_wc_variation_swatches_wc_notice() {
|
32 |
+
?>
|
33 |
+
|
34 |
+
<div class="error">
|
35 |
+
<p><?php esc_html_e( 'WooCommerce Variation Swatches is enabled but not effective. It requires WooCommerce in order to work.', 'wcvs' ); ?></p>
|
36 |
+
</div>
|
37 |
+
|
38 |
+
<?php
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
if ( ! function_exists( 'ta_wc_variation_swatches_pro_notice' ) ) {
|
43 |
+
/**
|
44 |
+
* Display notice in case of WooCommerce plugin is not activated
|
45 |
+
*/
|
46 |
+
function ta_wc_variation_swatches_pro_notice() {
|
47 |
+
?>
|
48 |
+
|
49 |
+
<div class="error">
|
50 |
+
<p><?php esc_html_e( 'No need to activate the free version of WooCommerce Variation Swatches plugin while the pro version is activated.', 'wcvs' ); ?></p>
|
51 |
+
</div>
|
52 |
+
|
53 |
+
<?php
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
if ( ! function_exists( 'ta_wc_variation_swatches_constructor' ) ) {
|
58 |
+
/**
|
59 |
+
* Construct plugin when plugins loaded in order to make sure WooCommerce API is fully loaded
|
60 |
+
* Check if WooCommerce is not activated then show an admin notice
|
61 |
+
* or create the main instance of plugin
|
62 |
+
*/
|
63 |
+
function ta_wc_variation_swatches_constructor() {
|
64 |
+
if ( ! function_exists( 'WC' ) ) {
|
65 |
+
add_action( 'admin_notices', 'ta_wc_variation_swatches_wc_notice' );
|
66 |
+
} elseif ( defined( 'TAWC_VS_PRO' ) ) {
|
67 |
+
add_action( 'admin_notices', 'ta_wc_variation_swatches_pro_notice' );
|
68 |
+
deactivate_plugins( plugin_basename( __FILE__ ) );
|
69 |
+
} else {
|
70 |
+
require_once plugin_dir_path( __FILE__ ) . '/includes/class-variation-swatches.php';
|
71 |
+
TA_WCVS();
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
if ( ! function_exists( 'ta_wc_variation_swatches_deactivate' ) ) {
|
77 |
+
/**
|
78 |
+
* Deactivation hook.
|
79 |
+
* Backup all unsupported types of attributes then reset them to "select".
|
80 |
+
*
|
81 |
+
* @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network
|
82 |
+
* or just the current site. Multisite only. Default is false.
|
83 |
+
*/
|
84 |
+
function ta_wc_variation_swatches_deactivate( $network_deactivating ) {
|
85 |
+
global $wpdb;
|
86 |
+
|
87 |
+
$blog_ids = array( 1 );
|
88 |
+
$original_blog_id = 1;
|
89 |
+
$network = false;
|
90 |
+
|
91 |
+
if ( is_multisite() && $network_deactivating ) {
|
92 |
+
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
|
93 |
+
$original_blog_id = get_current_blog_id();
|
94 |
+
$network = true;
|
95 |
+
}
|
96 |
+
|
97 |
+
foreach ( $blog_ids as $blog_id ) {
|
98 |
+
if ( $network ) {
|
99 |
+
switch_to_blog( $blog_id );
|
100 |
+
}
|
101 |
+
|
102 |
+
// Backup attribute types
|
103 |
+
$attributes = wc_get_attribute_taxonomies();
|
104 |
+
$default_types = array( 'text', 'select' );
|
105 |
+
$ta_wcvs_attributes = array();
|
106 |
+
|
107 |
+
if ( ! empty( $attributes ) ) {
|
108 |
+
foreach ( $attributes as $attribute ) {
|
109 |
+
if ( ! in_array( $attribute->attribute_type, $default_types ) ) {
|
110 |
+
$ta_wcvs_attributes[ $attribute->attribute_id ] = $attribute;
|
111 |
+
}
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
if ( ! empty( $ta_wcvs_attributes ) ) {
|
116 |
+
set_transient( 'tawcvs_attribute_taxonomies', $ta_wcvs_attributes );
|
117 |
+
delete_transient( 'wc_attribute_taxonomies' );
|
118 |
+
update_option( 'tawcvs_backup_attributes_time', time() );
|
119 |
+
}
|
120 |
+
|
121 |
+
// Reset attributes
|
122 |
+
if ( ! empty( $ta_wcvs_attributes ) ) {
|
123 |
+
foreach ( $ta_wcvs_attributes as $id => $attribute ) {
|
124 |
+
$wpdb->update(
|
125 |
+
$wpdb->prefix . 'woocommerce_attribute_taxonomies',
|
126 |
+
array( 'attribute_type' => 'select' ),
|
127 |
+
array( 'attribute_id' => $id ),
|
128 |
+
array( '%s' ),
|
129 |
+
array( '%d' )
|
130 |
+
);
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
// Delete the ignore restore
|
135 |
+
delete_option( 'tawcvs_ignore_restore_attributes' );
|
136 |
+
}
|
137 |
+
|
138 |
+
if ( $network ) {
|
139 |
+
switch_to_blog( $original_blog_id );
|
140 |
+
}
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
add_action( 'plugins_loaded', 'ta_wc_variation_swatches_constructor', 20 );
|
145 |
+
register_deactivation_hook( __FILE__, 'ta_wc_variation_swatches_deactivate' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|