Commit aa21f946 authored by Nahla Shiri's avatar Nahla Shiri

variation radio

parent 41b5ccf2
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
/*global wc_add_to_cart_variation_params, wc_cart_fragments_params */
;(function ( $, window, document, undefined ) {
/**
* VariationForm class which handles variation forms and attributes.
*/
var VariationForm = function( $form ) {
this.$form = $form;
this.$attributeGroups = $form.find( '.variations .value' );
this.$attributeFields = $form.find( '.variations input[type=radio]' );
this.$singleVariation = $form.find( '.single_variation' ),
this.$singleVariationWrap = $form.find( '.single_variation_wrap' );
this.$resetVariations = $form.find( '.reset_variations' );
this.$product = $form.closest( '.product' );
this.variationData = $form.data( 'product_variations' );
this.useAjax = false === this.variationData;
this.xhr = false;
// Initial state.
this.$singleVariationWrap.show();
this.$form.unbind( 'check_variations update_variation_values found_variation' );
this.$resetVariations.unbind( 'click' );
this.$attributeFields.unbind( 'change ' );
// Methods.
this.getChosenAttributes = this.getChosenAttributes.bind( this );
this.findMatchingVariations = this.findMatchingVariations.bind( this );
this.isMatch = this.isMatch.bind( this );
this.toggleResetLink = this.toggleResetLink.bind( this );
// Events.
$form.on( 'click', '.reset_variations', { variationForm: this }, this.onReset );
$form.on( 'reload_product_variations', { variationForm: this }, this.onReload );
$form.on( 'hide_variation', { variationForm: this }, this.onHide );
$form.on( 'show_variation', { variationForm: this }, this.onShow );
$form.on( 'click', '.single_add_to_cart_button', { variationForm: this }, this.onAddToCart );
$form.on( 'reset_data', { variationForm: this }, this.onResetDisplayedVariation );
$form.on( 'reset_image', { variationForm: this }, this.onResetImage );
$form.on( 'change', '.variations input[type=radio]', { variationForm: this }, this.onChange );
$form.on( 'found_variation', { variationForm: this }, this.onFoundVariation );
$form.on( 'check_variations', { variationForm: this }, this.onFindVariation );
$form.on( 'update_variation_values', { variationForm: this }, this.onUpdateAttributes );
// Check variations once init.
$form.trigger( 'check_variations' );
$form.trigger( 'wc_variation_form' );
};
/**
* Reset all fields.
*/
VariationForm.prototype.onReset = function( event ) {
event.preventDefault();
event.data.variationForm.$attributeFields.removeAttr('checked').change();
event.data.variationForm.$form.trigger( 'reset_data' );
};
/**
* Reload variation data from the DOM.
*/
VariationForm.prototype.onReload = function( event ) {
var form = event.data.variationForm;
form.variationData = form.$form.data( 'product_variations' );
form.useAjax = false === form.variationData;
form.$form.trigger( 'check_variations' );
};
/**
* When a variation is hidden.
*/
VariationForm.prototype.onHide = function( event ) {
event.preventDefault();
event.data.variationForm.$form.find( '.single_add_to_cart_button' ).removeClass( 'wc-variation-is-unavailable' ).addClass( 'disabled wc-variation-selection-needed' );
event.data.variationForm.$form.find( '.woocommerce-variation-add-to-cart' ).removeClass( 'woocommerce-variation-add-to-cart-enabled' ).addClass( 'woocommerce-variation-add-to-cart-disabled' );
};
/**
* When a variation is shown.
*/
VariationForm.prototype.onShow = function( event, variation, purchasable ) {
event.preventDefault();
if ( purchasable ) {
event.data.variationForm.$form.find( '.single_add_to_cart_button' ).removeClass( 'disabled wc-variation-selection-needed wc-variation-is-unavailable' );
event.data.variationForm.$form.find( '.woocommerce-variation-add-to-cart' ).removeClass( 'woocommerce-variation-add-to-cart-disabled' ).addClass( 'woocommerce-variation-add-to-cart-enabled' );
} else {
event.data.variationForm.$form.find( '.single_add_to_cart_button' ).removeClass( 'wc-variation-selection-needed' ).addClass( 'disabled wc-variation-is-unavailable' );
event.data.variationForm.$form.find( '.woocommerce-variation-add-to-cart' ).removeClass( 'woocommerce-variation-add-to-cart-enabled' ).addClass( 'woocommerce-variation-add-to-cart-disabled' );
}
};
/**
* When the cart button is pressed.
*/
VariationForm.prototype.onAddToCart = function( event ) {
if ( $( this ).is('.disabled') ) {
event.preventDefault();
if ( $( this ).is('.wc-variation-is-unavailable') ) {
window.alert( wc_add_to_cart_variation_params.i18n_unavailable_text );
} else if ( $( this ).is('.wc-variation-selection-needed') ) {
window.alert( wc_add_to_cart_variation_params.i18n_make_a_selection_text );
}
}
};
/**
* When displayed variation data is reset.
*/
VariationForm.prototype.onResetDisplayedVariation = function( event ) {
var form = event.data.variationForm;
form.$product.find( '.product_meta' ).find( '.sku' ).wc_reset_content();
form.$product.find( '.product_weight' ).wc_reset_content();
form.$product.find( '.product_dimensions' ).wc_reset_content();
form.$form.trigger( 'reset_image' );
form.$singleVariation.slideUp( 200 ).trigger( 'hide_variation' );
};
/**
* When the product image is reset.
*/
VariationForm.prototype.onResetImage = function( event ) {
event.data.variationForm.$form.wc_variations_image_update( false );
};
/**
* Looks for matching variations for current checked attributes.
*/
VariationForm.prototype.onFindVariation = function( event ) {
var form = event.data.variationForm,
attributes = form.getChosenAttributes(),
currentAttributes = attributes.data;
if ( attributes.count === attributes.chosenCount ) {
if ( form.useAjax ) {
if ( form.xhr ) {
form.xhr.abort();
}
form.$form.block( { message: null, overlayCSS: { background: '#fff', opacity: 0.6 } } );
currentAttributes.product_id = parseInt( form.$form.data( 'product_id' ), 10 );
currentAttributes.custom_data = form.$form.data( 'custom_data' );
form.xhr = $.ajax( {
url: wc_cart_fragments_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_variation' ),
type: 'POST',
data: currentAttributes,
success: function( variation ) {
if ( variation ) {
form.$form.trigger( 'found_variation', [ variation ] );
} else {
form.$form.trigger( 'reset_data' );
form.$form.find( '.single_variation' ).after( '<p class="wc-no-matching-variations woocommerce-info">' + wc_add_to_cart_variation_params.i18n_no_matching_variations_text + '</p>' );
form.$form.find( '.wc-no-matching-variations' ).slideDown( 200 );
}
},
complete: function() {
form.$form.unblock();
}
} );
} else {
form.$form.trigger( 'update_variation_values' );
var matching_variations = form.findMatchingVariations( form.variationData, currentAttributes ),
variation = matching_variations.shift();
if ( variation ) {
form.$form.trigger( 'found_variation', [ variation ] );
} else {
form.$form.trigger( 'reset_data' );
form.$form.find( '.single_variation' ).after( '<p class="wc-no-matching-variations woocommerce-info">' + wc_add_to_cart_variation_params.i18n_no_matching_variations_text + '</p>' );
form.$form.find( '.wc-no-matching-variations' ).slideDown( 200 );
}
}
} else {
form.$form.trigger( 'update_variation_values' );
form.$form.trigger( 'reset_data' );
}
// Show reset link.
form.toggleResetLink( attributes.chosenCount > 0 );
};
/**
* Triggered when a variation has been found which matches all attributes.
*/
VariationForm.prototype.onFoundVariation = function( event, variation ) {
var form = event.data.variationForm,
$sku = form.$product.find( '.product_meta' ).find( '.sku' ),
$weight = form.$product.find( '.product_weight' ),
$dimensions = form.$product.find( '.product_dimensions' ),
$qty = form.$singleVariationWrap.find( '.quantity' ),
purchasable = true,
variation_id = '',
template = false,
$template_html = '';
if ( variation.sku ) {
$sku.wc_set_content( variation.sku );
} else {
$sku.wc_reset_content();
}
if ( variation.weight ) {
$weight.wc_set_content( variation.weight );
} else {
$weight.wc_reset_content();
}
if ( variation.dimensions ) {
$dimensions.wc_set_content( variation.dimensions );
} else {
$dimensions.wc_reset_content();
}
form.$form.wc_variations_image_update( variation );
if ( ! variation.variation_is_visible ) {
template = wp.template( 'unavailable-variation-template' );
} else {
template = wp.template( 'variation-template' );
variation_id = variation.variation_id;
}
$template_html = template( {
variation: variation
} );
$template_html = $template_html.replace( '/*<![CDATA[*/', '' );
$template_html = $template_html.replace( '/*]]>*/', '' );
form.$singleVariation.html( $template_html );
form.$form.find( 'input[name="variation_id"], input.variation_id' ).val( variation.variation_id ).change();
// Hide or show qty input
if ( variation.is_sold_individually === 'yes' ) {
$qty.find( 'input.qty' ).val( '1' ).attr( 'min', '1' ).attr( 'max', '' );
$qty.hide();
} else {
$qty.find( 'input.qty' ).attr( 'min', variation.min_qty ).attr( 'max', variation.max_qty );
$qty.show();
}
// Enable or disable the add to cart button
if ( ! variation.is_purchasable || ! variation.is_in_stock || ! variation.variation_is_visible ) {
purchasable = false;
}
// Reveal
if ( $.trim( form.$singleVariation.text() ) ) {
form.$singleVariation.slideDown( 200 ).trigger( 'show_variation', [ variation, purchasable ] );
} else {
form.$singleVariation.show().trigger( 'show_variation', [ variation, purchasable ] );
}
};
/**
* Triggered when an attribute field changes.
*/
VariationForm.prototype.onChange = function( event ) {
var form = event.data.variationForm;
form.$form.find( 'input[name="variation_id"], input.variation_id' ).val( '' ).change();
form.$form.find( '.wc-no-matching-variations' ).remove();
if ( form.useAjax ) {
form.$form.trigger( 'check_variations' );
} else {
form.$form.trigger( 'woocommerce_variation_select_change' );
form.$form.trigger( 'check_variations' );
$( this ).blur();
}
// Custom event for when variation selection has been changed
form.$form.trigger( 'woocommerce_variation_has_changed' );
};
/**
* Escape quotes in a string.
* @param {string} string
* @return {string}
*/
VariationForm.prototype.addSlashes = function( string ) {
string = string.replace( /'/g, '\\\'' );
string = string.replace( /"/g, '\\\"' );
return string;
};
/**
* Updates attributes in the DOM to show valid values.
*/
VariationForm.prototype.onUpdateAttributes = function( event ) {
var form = event.data.variationForm,
attributes = form.getChosenAttributes(),
currentAttributes = attributes.data;
if ( form.useAjax ) {
return;
}
// Loop through radio buttons and disable/enable based on selections.
form.$attributeGroups.each( function( index, el ) {
var current_attr = $( el ),
$fields = current_attr.find( 'input[type=radio]' ),
current_attr_name = $fields.data( 'attribute_name' ) || $fields.attr( 'name' );
// The attribute of this radio button should not be taken into account when calculating its matching variations:
// The constraints of this attribute are shaped by the values of the other attributes.
var checkAttributes = $.extend( true, {}, currentAttributes );
checkAttributes[ current_attr_name ] = '';
var variations = form.findMatchingVariations( form.variationData, checkAttributes );
$fields.attr( 'disabled', 'disabled' );
// Loop through variations.
for ( var num in variations ) {
if ( typeof( variations[ num ] ) !== 'undefined' && variations[ num ].variation_is_active ) {
var variationAttributes = variations[ num ].attributes;
for ( var attr_name in variationAttributes ) {
if ( variationAttributes.hasOwnProperty( attr_name ) && attr_name === current_attr_name ) {
var attr_val = variationAttributes[ attr_name ];
if ( attr_val ) {
// Remove disabled.
$fields.filter( '[value="' + form.addSlashes( attr_val ) + '"]' ).removeAttr( 'disabled' );
} else {
// Enable all radio buttons of attribute.
$fields.removeAttr( 'disabled' );
}
}
}
}
}
});
// Custom event for when variations have been updated.
form.$form.trigger( 'woocommerce_update_variation_values' );
};
/**
* Get chosen attributes from form.
* @return array
*/
VariationForm.prototype.getChosenAttributes = function() {
var data = {};
var count = 0;
var chosen = 0;
this.$attributeGroups.each( function() {
var $fields = $( this ).find( 'input[type=radio]' );
var attribute_name = $fields.data( 'attribute_name' ) || $fields.attr( 'name' );
var value = $fields.filter(':checked').val() || '';
if ( value.length > 0 ) {
chosen ++;
}
count ++;
data[ attribute_name ] = value;
});
return {
'count' : count,
'chosenCount': chosen,
'data' : data
};
};
/**
* Find matching variations for attributes.
*/
VariationForm.prototype.findMatchingVariations = function( variations, attributes ) {
var matching = [];
for ( var i = 0; i < variations.length; i++ ) {
var variation = variations[i];
if ( this.isMatch( variation.attributes, attributes ) ) {
matching.push( variation );
}
}
return matching;
};
/**
* See if attributes match.
* @return {Boolean}
*/
VariationForm.prototype.isMatch = function( variation_attributes, attributes ) {
var match = true;
for ( var attr_name in variation_attributes ) {
if ( variation_attributes.hasOwnProperty( attr_name ) ) {
var val1 = variation_attributes[ attr_name ];
var val2 = attributes[ attr_name ];
if ( val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2 ) {
match = false;
}
}
}
return match;
};
/**
* Show or hide the reset link.
*/
VariationForm.prototype.toggleResetLink = function( on ) {
if ( on ) {
if ( this.$resetVariations.css( 'visibility' ) === 'hidden' ) {
this.$resetVariations.css( 'visibility', 'visible' ).hide().fadeIn();
}
} else {
this.$resetVariations.css( 'visibility', 'hidden' );
}
};
/**
* Function to call wc_variation_form on jquery selector.
*/
$.fn.wc_variation_form = function() {
new VariationForm( this );
return this;
};
/**
* Stores the default text for an element so it can be reset later
*/
$.fn.wc_set_content = function( content ) {
if ( undefined === this.attr( 'data-o_content' ) ) {
this.attr( 'data-o_content', this.text() );
}
this.text( content );
};
/**
* Stores the default text for an element so it can be reset later
*/
$.fn.wc_reset_content = function() {
if ( undefined !== this.attr( 'data-o_content' ) ) {
this.text( this.attr( 'data-o_content' ) );
}
};
/**
* Stores a default attribute for an element so it can be reset later
*/
$.fn.wc_set_variation_attr = function( attr, value ) {
if ( undefined === this.attr( 'data-o_' + attr ) ) {
this.attr( 'data-o_' + attr, ( ! this.attr( attr ) ) ? '' : this.attr( attr ) );
}
if ( false === value ) {
this.removeAttr( attr );
} else {
this.attr( attr, value );
}
};
/**
* Reset a default attribute for an element so it can be reset later
*/
$.fn.wc_reset_variation_attr = function( attr ) {
if ( undefined !== this.attr( 'data-o_' + attr ) ) {
this.attr( attr, this.attr( 'data-o_' + attr ) );
}
};
/**
* Reset the slide position if the variation has a different image than the current one
*/
$.fn.wc_maybe_trigger_slide_position_reset = function( variation ) {
var $form = $( this ),
$product = $form.closest( '.product' ),
$product_gallery = $product.find( '.images' ),
reset_slide_position = false,
new_image_id = ( variation && variation.image_id ) ? variation.image_id : '';
if ( $form.attr( 'current-image' ) !== new_image_id ) {
reset_slide_position = true;
}
$form.attr( 'current-image', new_image_id );
if ( reset_slide_position ) {
$product_gallery.trigger( 'woocommerce_gallery_reset_slide_position' );
}
};
/**
* Sets product images for the chosen variation
*/
$.fn.wc_variations_image_update = function( variation ) {
var $form = this,
$product = $form.closest( '.product' ),
$product_gallery = $product.find( '.images' ),
$gallery_img = $product.find( '.flex-control-nav li:eq(0) img' ),
$product_img_wrap = $product_gallery.find( '.woocommerce-product-gallery__image, .woocommerce-product-gallery__image--placeholder' ).eq( 0 ),
$product_img = $product_img_wrap.find( '.wp-post-image' ),
$product_link = $product_img_wrap.find( 'a' ).eq( 0 );
if ( variation && variation.image && variation.image.src && variation.image.src.length > 1 ) {
$product_img.wc_set_variation_attr( 'src', variation.image.src );
$product_img.wc_set_variation_attr( 'height', variation.image.src_h );
$product_img.wc_set_variation_attr( 'width', variation.image.src_w );
$product_img.wc_set_variation_attr( 'srcset', variation.image.srcset );
$product_img.wc_set_variation_attr( 'sizes', variation.image.sizes );
$product_img.wc_set_variation_attr( 'title', variation.image.title );
$product_img.wc_set_variation_attr( 'alt', variation.image.alt );
$product_img.wc_set_variation_attr( 'data-src', variation.image.full_src );
$product_img.wc_set_variation_attr( 'data-large_image', variation.image.full_src );
$product_img.wc_set_variation_attr( 'data-large_image_width', variation.image.full_src_w );
$product_img.wc_set_variation_attr( 'data-large_image_height', variation.image.full_src_h );
$product_img_wrap.wc_set_variation_attr( 'data-thumb', variation.image.src );
$gallery_img.wc_set_variation_attr( 'src', variation.image.thumb_src );
$product_link.wc_set_variation_attr( 'href', variation.image.full_src );
} else {
$product_img.wc_reset_variation_attr( 'src' );
$product_img.wc_reset_variation_attr( 'width' );
$product_img.wc_reset_variation_attr( 'height' );
$product_img.wc_reset_variation_attr( 'srcset' );
$product_img.wc_reset_variation_attr( 'sizes' );
$product_img.wc_reset_variation_attr( 'title' );
$product_img.wc_reset_variation_attr( 'alt' );
$product_img.wc_reset_variation_attr( 'data-src' );
$product_img.wc_reset_variation_attr( 'data-large_image' );
$product_img.wc_reset_variation_attr( 'data-large_image_width' );
$product_img.wc_reset_variation_attr( 'data-large_image_height' );
$product_img_wrap.wc_reset_variation_attr( 'data-thumb' );
$gallery_img.wc_reset_variation_attr( 'src' );
$product_link.wc_reset_variation_attr( 'href' );
}
window.setTimeout( function() {
$product_gallery.trigger( 'woocommerce_gallery_init_zoom' );
$form.wc_maybe_trigger_slide_position_reset( variation );
$( window ).trigger( 'resize' );
}, 10 );
};
$(function() {
if ( typeof wc_add_to_cart_variation_params !== 'undefined' ) {
$( '.variations_form' ).each( function() {
$( this ).wc_variation_form();
});
}
});
/**
* Matches inline variation objects to chosen attributes
* @deprecated 2.6.9
* @type {Object}
*/
var wc_variation_form_matcher = {
find_matching_variations: function( product_variations, settings ) {
var matching = [];
for ( var i = 0; i < product_variations.length; i++ ) {
var variation = product_variations[i];
if ( wc_variation_form_matcher.variations_match( variation.attributes, settings ) ) {
matching.push( variation );
}
}
return matching;
},
variations_match: function( attrs1, attrs2 ) {
var match = true;
for ( var attr_name in attrs1 ) {
if ( attrs1.hasOwnProperty( attr_name ) ) {
var val1 = attrs1[ attr_name ];
var val2 = attrs2[ attr_name ];
if ( val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2 ) {
match = false;
}
}
}
return match;
}
};
})( jQuery, window, document );
=== WC Variations Radio Buttons ===
Contributors: mantish
Donate link: mailto:paypal@8manos.com
Tags: woocommerce, variations, woocommerce variations, radio buttons, variations radio, variations radio buttons
Requires at least: 4.4
Tested up to: 4.7.4
Stable tag: 2.0.0
WC requires at least: 3.0
WC tested up to: 3.0.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Variations Radio Buttons for WooCommerce. Let your customers choose product variations using radio buttons instead of dropdowns.
== Description ==
Radio buttons are more friendly than dropdown selects. This plugin will help you have a better UX in your WooCommerce site, as your customers will see all your variations without having to click on a dropdown.
The radio buttons will be toggled dinamically so your customers won't be able to choose non existent variations.
### Theme Compatibility
This plugin may not work out of the box with some themes. This is due to a theme having its own template for variation selection (single-product/add-to-cart/variable.php).
To make this plugin work with a non compatible theme, a [child theme](http://themify.me/docs/child-themes) has to be created.
Then copy plugins/wc-variations-radio-buttons/templates/single-product/add-to-cart/variable.php to themes/your-child-theme/woocommerce/single-product/add-to-cart/variable.php
### Github
Source code and contributions at [github](https://github.com/8manos/wc-variations-radio-buttons)
== Changelog ==
= 2.0.0 =
* Updated to match changes in WooCommerce 3.0.
* This version is not compatible with WooCommerce 2.x.
* Fix issues with the variation image not changing.
= 1.1.5 =
* Fix error when using product_page WooCommerce shortcode.
* Show alert when clicking disabled add to cart button.
= 1.1.4 =
* Avoid overwriting of custom add-to-cart button.
= 1.1.3 =
* Fixes clear button that got screwed on last version.
= 1.1.2 =
* Updated to match changes in WooCommerce 2.5.
* Image disappearing in certain themes fixed.
= 1.1.1 =
* Support for responsive images as in WordPress 4.4 and WooCommerce 2.4.11.
* Checked compatibility with WooCommerce 2.5.0-RC1.
= 1.1.0 =
* Full compatibility with WooCommerce 2.4.
* Variations are called via AJAX when there are many variations.
* Changed version requirements: At least WordPress 4.1 and WooCommerce 2.4.
= 1.0.3 =
* Now works with woocommerce_variation_is_active filter.
* Fix bug that prevented the plugin to work with custom attributes.
* Hopefuly no more "The plugin does not have a valid header." message.
= 1.0.2 =
* Now works better with some themes.
= 1.0.1 =
* WooCommerce 2.4 compatibility.
= 1.0 =
* First release.
\ No newline at end of file
<?php
/**
* Variable product add to cart
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.5.0
*
* Modified to use radio buttons instead of dropdowns
* @author 8manos
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'print_attribute_radio' ) ) {
function print_attribute_radio( $checked_value, $value, $label, $name ) {
// This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
$checked = sanitize_title( $checked_value ) === $checked_value ? checked( $checked_value, sanitize_title( $value ), false ) : checked( $checked_value, $value, false );
$input_name = 'attribute_' . esc_attr( $name ) ;
$esc_value = esc_attr( $value );
$id = esc_attr( $name . '_v_' . $value );
$filtered_label = apply_filters( 'woocommerce_variation_option_name', $label );
printf( '<div><input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s><label for="%3$s">%5$s</label></div>', $input_name, $esc_value, $id, $checked, $filtered_label );
}
}
global $product;
$attribute_keys = array_keys( $attributes );
do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo htmlspecialchars( wp_json_encode( $available_variations ) ) ?>">
<?php do_action( 'woocommerce_before_variations_form' ); ?>
<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
<p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
<?php else : ?>
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $name ); ?>"><?php echo wc_attribute_label( $name ); ?></label></td>
<?php
$sanitized_name = sanitize_title( $name );
if ( isset( $_REQUEST[ 'attribute_' . $sanitized_name ] ) ) {
$checked_value = $_REQUEST[ 'attribute_' . $sanitized_name ];
} elseif ( isset( $selected_attributes[ $sanitized_name ] ) ) {
$checked_value = $selected_attributes[ $sanitized_name ];
} else {
$checked_value = '';
}
?>
<td class="value">
<?php
if ( ! empty( $options ) ) {
if ( taxonomy_exists( $name ) ) {
// Get terms if this is a taxonomy - ordered. We need the names too.
$terms = wc_get_product_terms( $product->get_id(), $name, array( 'fields' => 'all' ) );
foreach ( $terms as $term ) {
if ( ! in_array( $term->slug, $options ) ) {
continue;
}
print_attribute_radio( $checked_value, $term->slug, $term->name, $sanitized_name );
}
} else {
foreach ( $options as $option ) {
print_attribute_radio( $checked_value, $option, $option, $sanitized_name );
}
}
}
echo end( $attribute_keys ) === $name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __( 'Clear', 'woocommerce' ) . '</a>' ) : '';
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<div class="single_variation_wrap">
<?php
do_action( 'woocommerce_before_single_variation' );
do_action( 'woocommerce_single_variation' );
do_action( 'woocommerce_after_single_variation' );
?>
</div>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
<?php endif; ?>
<?php do_action( 'woocommerce_after_variations_form' ); ?>
</form>
<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
<?php
/**
* Plugin Name: WC Variations Radio Buttons
* Plugin URI: https://wordpress.org/plugins/wc-variations-radio-buttons/
* Description: Variations Radio Buttons for WooCommerce. Let your customers choose product variations using radio buttons instead of dropdowns.
* Version: 2.0.0
* Author: 8manos
* Author URI: http://8manos.com
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Check if WooCommerce is active
if ( is_plugin_active( 'woocommerce/woocommerce.php') ) {
class WC_Radio_Buttons {
// plugin version
const VERSION = '2.0.0';
private $plugin_path;
private $plugin_url;
public function __construct() {
add_filter( 'woocommerce_locate_template', array( $this, 'locate_template' ), 10, 3 );
//js scripts
add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ), 999 );
}
public function get_plugin_path() {
if ( $this->plugin_path ) {
return $this->plugin_path;
}
return $this->plugin_path = plugin_dir_path( __FILE__ );
}
public function get_plugin_url() {
if ( $this->plugin_url ) {
return $this->plugin_url;
}
return $this->plugin_url = plugin_dir_url( __FILE__ );
}
public function locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
$_template = $template;
if ( ! $template_path ) {
$template_path = $woocommerce->template_url;
}
$plugin_path = $this->get_plugin_path() . 'templates/';
// Look within passed path within the theme - this is priority
$template = locate_template( array(
$template_path . $template_name,
$template_name
) );
// Modification: Get the template from this plugin, if it exists
if ( ! $template && file_exists( $plugin_path . $template_name ) ) {
$template = $plugin_path . $template_name;
}
// Use default template
if ( ! $template ) {
$template = $_template;
}
return $template;
}
function load_scripts() {
wp_deregister_script( 'wc-add-to-cart-variation' );
wp_register_script( 'wc-add-to-cart-variation', $this->get_plugin_url() . 'assets/js/frontend/add-to-cart-variation.js', array( 'jquery', 'wp-util' ), self::VERSION );
}
}
new WC_Radio_Buttons();
}
\ No newline at end of file
......@@ -4,9 +4,17 @@ jQuery( document ).ready( function() {
var download_link = jQuery( '.download_file_link' ).attr('href');
var variation_id = jQuery( 'input[name="variation_id"]' ).val();
var link = download_link+'?variation_id='+variation_id;
alert(link);
window.location.href= link;
return false;
});
jQuery('.color-list').each(function (index, value) {
var color = jQuery(this).find('input').attr('data-color');
jQuery(this).find('input[type=radio]:after').css('background-color',color);
});
});
\ No newline at end of file
......@@ -335,6 +335,28 @@ function nap_variation_color($variationID) {
return $color;
}
function nap_color_attribute($name){
$term = get_term_by('slug',$name, 'pa_couleur');
$termID = $term->term_id;
$color = get_field('couleurs', 'pa_couleur_' . $termID);
return $color;
}
function nap_icon_format($name){
$icons = array();
$term = get_term_by('slug',$name, 'pa_format');
$termID = $term->term_id;
$active = get_field('format_icone_active', 'pa_format_' . $termID);
$inactive = get_field('format_icone_inactive', 'pa_format_' . $termID);
$icons['active']=$active;
$icons['inactive']=$inactive;
return $icons;
}
function nap_distinct_color_variations($variations) {
$var_colors = array();
foreach ($variations as $variation) :
......@@ -347,6 +369,30 @@ function nap_distinct_color_variations($variations) {
return $var_colors;
}
function nap_variation_format($variationID) {
$variable_product = wc_get_product($variationID);
return $variable_product->get_attribute('format');
}
function nap_distinct_format_variations($variations) {
$var_format = array();
foreach ($variations as $variation) :
$variation_ID = $variation['variation_id'];
$format_name = nap_variation_format($variation_ID);
$term = get_term_by('name', $format_name, 'pa_format');
$termID = $term->term_id;
if (!in_array($termID, $var_format)):
$var_format[$termID] = $format_name;
endif;
endforeach;
// print_r($var_format);
return $var_format;
}
function nap_get_item($post_ID, $args = null, $current_page = '', $options = null) {
$link = $image = $size = '';
if (isset($options)) {
......@@ -391,3 +437,21 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
}
remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
function nap_upload_image($img){
return trim(strtolower($img));
}
function nap_print_attribute_radio( $checked_value, $value, $label, $name ) {
$checked = sanitize_title( $checked_value ) === $checked_value ? checked( $checked_value, sanitize_title( $value ), false ) : checked( $checked_value, $value, false );
$input_name = 'attribute_' . esc_attr( $name ) ;
$esc_value = esc_attr( $value );
$id = esc_attr( $name . '_v_' . $value );
$filtered_label = apply_filters( 'woocommerce_variation_option_name', $label );
printf( '<div><input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s><label for="%3$s">%5$s</label></div>', $input_name, $esc_value, $id, $checked, $filtered_label );
}
\ No newline at end of file
<style>
.color-list input[type='radio']:after {
position: relative;
background-color: #d1d3d1;
content: '';
bottom: 14px;
margin-bottom: 50px;
height: 36px;
width: 36px;
display: inline-block;
border-radius: 50%;
visibility: visible;
border: 1px solid transparent;
}
.color-list input[type='radio']{
text-align: center;
margin-bottom: 20px;
}
.color-list input[type='radio']:checked:after {
border: 1px solid #071D3D;
}
.format-list input[type='radio'],.color-list input[type='radio'] {
margin:0;padding:0;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
}
.format-label {
cursor:pointer;
background-size:contain;
background-repeat:no-repeat;
display:inline-block;
width:100px;
height:70px;
}
.reset_variations, .quantity{
display: none !important;
}
</style>
<?php
print_r($_POST);
/**
* Variable product add to cart
*
......@@ -15,19 +66,43 @@
* @package WooCommerce/Templates
* @version 3.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
if (!defined('ABSPATH')) {
exit;
}
global $product;
$attribute_keys = array_keys( $attributes );
$attribute_keys = array_keys($attributes);
$product_cats = array_reverse(wp_get_post_terms($product->get_id(), 'product_cat'));
$subcat_iD = $product_cats[1]->term_id;
//do_action( 'woocommerce_before_add_to_cart_form' ); ?>
if (!function_exists('print_attribute_radio')) {
function print_attribute_radio($checked_value, $value, $label, $name) {
$checked = sanitize_title($checked_value) === $checked_value ? checked($checked_value, sanitize_title($value), false) : checked($checked_value, $value, false);
$input_name = 'attribute_' . esc_attr($name);
$esc_value = esc_attr($value);
$id = esc_attr($name . '_v_' . $value);
if ($name == 'pa_couleur') {
$hexa = nap_color_attribute($value);
$filtered_label = apply_filters('woocommerce_variation_option_name', $label);
printf(' <style>
#' . $id . ':after { background-color: ' . $hexa . '; }
</style><li class="color-list" data-color="' . $hexa . '"><input data-color="' . $hexa . '" type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s><span data-color="' . $hexa . '"></span></li>', $input_name, $esc_value, $id, $checked, $filtered_label);
} else {
$icons = nap_icon_format($value);
$filtered_label = apply_filters('woocommerce_variation_option_name', $label);
printf('<li class="format-list"><input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s><label class="format-label" style="background:url(' . $icons['inactive'] . ')" for="%3$s"></label></li>', $input_name, $esc_value, $id, $checked, $filtered_label);
}
}
}
do_action('woocommerce_before_add_to_cart_form');
?>
<div id="product" class="clearfix">
<div class="product-images row animated">
......@@ -36,8 +111,8 @@ $subcat_iD = $product_cats[1]->term_id;
</div>
<div class="product-slides">
<div class="product-header">
<h2 class="crete -italic font-small">Serviettes Céli-ouate</h2>
<h3 class="crete">Gamme <?php the_title();?></h3>
<h2 class="crete -italic font-small"><?php echo $product_cats[1]->name ?></h2>
<h3 class="crete"><?php the_title(); ?></h3>
</div>
<div class="nav-slider transition">
<ul>
......@@ -51,10 +126,11 @@ $subcat_iD = $product_cats[1]->term_id;
<?php
$variations = $product->get_available_variations();
$var_colors = nap_distinct_color_variations($variations);
foreach ($var_colors as $key => $value) : ?>
<div class="image element-slider easyzoom easyzoom--overlay easyzoom--with-toggle" data-color = "<?php echo $value?>" data-slick-index = "1">
<a href="<?php echo get_the_post_thumbnail_url($key, 'full')?>">
<img src="<?php echo get_the_post_thumbnail_url($key, 'medium')?>" alt="" />
foreach ($var_colors as $key => $value) :
?>
<div class="image element-slider easyzoom easyzoom--overlay easyzoom--with-toggle" data-color = "<?php echo $value ?>" data-slick-index = "1">
<a href="<?php echo get_the_post_thumbnail_url($key, 'full') ?>">
<img src="<?php echo get_the_post_thumbnail_url($key, 'medium') ?>" alt="" />
</a>
</div>
......@@ -63,26 +139,24 @@ $subcat_iD = $product_cats[1]->term_id;
?>
<?php
if( get_field('images_ambiance','product_cat_'.$subcat_iD) ):
if (get_field('images_ambiance', 'product_cat_' . $subcat_iD)):
$ambiance = array();
while ( has_sub_field('images_ambiance','product_cat_'.$subcat_iD) ) :
$image_amb= get_sub_field('img_ab');
$ambiance []= $image_amb;
$attachment = wp_get_attachment_image_src($image_amb,'medium');
$hd = wp_get_attachment_image_src($image_amb,'full');
while (has_sub_field('images_ambiance', 'product_cat_' . $subcat_iD)) :
$image_amb = get_sub_field('img_ab');
$ambiance [] = $image_amb;
$attachment = wp_get_attachment_image_src($image_amb, 'medium');
$hd = wp_get_attachment_image_src($image_amb, 'full');
?>
<div class="image element-slider easyzoom easyzoom--overlay easyzoom--with-toggle" data-color = "<?php echo $color?>" data-slick-index = "1">
<a href="<?php echo $hd[0];?>">
<img src="<?php echo $attachment[0] ;?>" alt="" />
<div class="image element-slider easyzoom easyzoom--overlay easyzoom--with-toggle" data-color = "<?php echo $color ?>" data-slick-index = "1">
<a href="<?php echo $hd[0]; ?>">
<img src="<?php echo $attachment[0]; ?>" alt="" />
</a>
</div>
<?php
endwhile;
endif;?>
endif;
?>
</div>
<div class="gallery clearfix">
......@@ -90,23 +164,24 @@ $subcat_iD = $product_cats[1]->term_id;
<span class="close-btn"></span>
<?php foreach ($var_colors as $key => $value) : ?>
<article class = "row" data-color = "<?php echo $value;?>">
<a href="<?php echo get_the_post_thumbnail_url($key, 'full')?>"></a>
<article class = "row" data-color = "<?php echo $value; ?>">
<a href="<?php echo get_the_post_thumbnail_url($key, 'full') ?>"></a>
<figure>
<img src="<?php echo get_the_post_thumbnail_url($key, 'medium')?>" alt="" title="">
<img src="<?php echo get_the_post_thumbnail_url($key, 'medium') ?>" alt="" title="">
</figure>
</article>
<?php endforeach;
<?php
endforeach;
foreach ($ambiance as $key => $value) :
$attachment = wp_get_attachment_image_src($value,'medium');
$hd = wp_get_attachment_image_src($value,'full');
$attachment = wp_get_attachment_image_src($value, 'medium');
$hd = wp_get_attachment_image_src($value, 'full');
?>
<article class = "row" data-color = "red">
<a class = "download-btn" href="<?php echo $hd[0];?>" download></a>
<a class = "download-btn" href="<?php echo $hd[0]; ?>" download></a>
<figure>
<img src="<?php echo $attachment[0] ;?>" alt="" title="">
<img src="<?php echo $attachment[0]; ?>" alt="" title="">
</figure>
</article>
<?php endforeach; ?>
......@@ -116,18 +191,91 @@ $subcat_iD = $product_cats[1]->term_id;
</div>
</div>
</div>
</div>
</div>
<div class="product-details full-height row right clearfix transition">
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint($product->get_id()); ?>" data-product_variations="<?php echo htmlspecialchars(wp_json_encode($available_variations)) ?>">
<?php do_action('woocommerce_before_variations_form'); ?>
<div class="product-details full-height row right clearfix transition">
<?php if (empty($available_variations) && false !== $available_variations) : ?>
<p class="stock out-of-stock"><?php _e('This product is currently out of stock and unavailable.', 'woocommerce'); ?></p>
<?php else : ?>
<div class="variations" cellspacing="0">
<?php foreach ($attributes as $name => $options) : ?>
<div class="list row list-color left border-l">
<div class="product-header center font-small label">
<label for="<?php echo sanitize_title($name); ?>" class = "chevron bottom">Choix de la <?php echo wc_attribute_label($name); ?></label>
</div>
<?php
$sanitized_name = sanitize_title($name);
if (isset($_REQUEST['attribute_' . $sanitized_name])) {
$checked_value = $_REQUEST['attribute_' . $sanitized_name];
} elseif (isset($selected_attributes[$sanitized_name])) {
$checked_value = $selected_attributes[$sanitized_name];
} else {
$checked_value = '';
}
?>
<ul class="value">
<?php
if (!empty($options)) {
if (taxonomy_exists($name)) {
// Get terms if this is a taxonomy - ordered. We need the names too.
$terms = wc_get_product_terms($product->get_id(), $name, array('fields' => 'all'));
foreach ($terms as $term) {
if (!in_array($term->slug, $options)) {
continue;
}
print_attribute_radio($checked_value, $term->slug, $term->name, $sanitized_name);
}
} else {
foreach ($options as $option) {
print_attribute_radio($checked_value, $option, $option, $sanitized_name);
}
}
}
echo end($attribute_keys) === $name ? apply_filters('woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __('Clear', 'woocommerce') . '</a>') : '';
?>
</ul>
</div>
<?php endforeach; ?>
</div>
<?php do_action('woocommerce_before_add_to_cart_button'); ?>
<div class="single_variation_wrap">
<?php
do_action('woocommerce_before_single_variation');
do_action('woocommerce_single_variation');
do_action('woocommerce_after_single_variation');
?>
</div>
<?php do_action('woocommerce_after_add_to_cart_button'); ?>
<?php endif; ?>
<?php do_action('woocommerce_after_variations_form'); ?>
<!--<div class="list row list-color left border-l">
<div class="product-header center font-small">
<span class = "chevron bottom">Choix de la couleur</span>
</div>
<ul>
<?php foreach ($var_colors as $key => $value) : ?>
<li class = ""><span data-color="<?php echo $value;?>"></span></li>
<?php endforeach;?>
<?php
foreach ($var_colors as $key => $value) :
$variable_product = wc_get_product($key);
?>
<li class = "" data-name='<?php echo $variable_product->get_attribute('couleur'); ?>'><span data-color="<?php echo $value; ?>"></span></li>
<?php endforeach; ?>
</ul>
</div>
......@@ -136,32 +284,20 @@ $subcat_iD = $product_cats[1]->term_id;
<span class = "chevron bottom">Choix du format</span>
</div>
<ul>
<li class ="disabled">
<span class= "format-img" data-width = "16" data-height = "22" ></span>
<div class="format-desc">16x22 cm pliage en Z</div>
</li>
<li>
<span class= "format-img" data-width = "20" data-height = "20" ></span>
<div class="format-desc">20x20 cm <br> 2 feuilles</div>
</li>
<li>
<span class= "format-img" data-width = "30" data-height = "30" ></span>
<div class="format-desc">30x30 cm <br> 2 feuilles</div>
</li>
<li>
<span class= "format-img" data-width = "30" data-height = "39" ></span>
<div class="format-desc">30x39 cm <br> 2 feuilles</div>
</li>
<li>
<span class= "format-img" data-width = "33" data-height = "33" ></span>
<div class="format-desc">33x33 cm <br> 2 feuilles</div>
</li>
<li>
<span class= "format-img" data-width = "39" data-height = "39" ></span>
<div class="format-desc">39x39 cm <br> 2 feuilles</div>
<?php
$formats_tab = nap_distinct_format_variations($variations);
foreach ($formats_tab as $key => $value) :
$icons = nap_icon_format($key);
$term = get_term_by('name', $value, 'pa_format');
// print_r($term);
?>
<li class ="" data-format='<?php echo $term->slug; ?>'>
<img src="<?php echo $icons['inactive'] ?>" data-img = "<?php echo $icons['inactive'] ?>" data-img-active = '<?php echo $icons['active'] ?>'>
<div class="format-desc"><?php echo $value ?></div>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>-->
<div class="product-info row center left border-l">
<div class="info-content">
......@@ -172,19 +308,41 @@ $subcat_iD = $product_cats[1]->term_id;
<p>18 paquets de 100</p>
</div>
<div class="price">
<span class="crete">45 € ht</span>
<span class="crete"><?php echo $product->get_price_html(); ?> ht</span>
<div class="notice">( prix public conseillé )</div>
<div class="font-small">785226</div>
<div class="font-small">
<div class="product_meta">
<?php do_action( 'woocommerce_product_meta_start' ); ?>
<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
<span class="sku_wrapper"><span class="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' ); ?></span></span>
<?php endif; ?>
<?php do_action( 'woocommerce_product_meta_end' ); ?>
</div>
</div>
</div>
</div>
<div class = "btn-list">
<div class="btn pink-btn rounded">Nous contacter</div>
<div class="btn pink-btn rounded download-btn">Télécharger la fiche technique</div>
<div class="btn pink-btn rounded download-btn">
<a href="<?php echo get_permalink(43); ?>" class="hidden download_file_link"></a>
<a href="#" class="download_file">Télécharger la fiche technique </a>
</div>
</div>
<div class="font-small circle-btn add-icon show-product"><span class= "abs-center">Produits associées</span></div>
</div>
</div>
<div class="product-list transition border-l fixed">
</form>
</div>
<div class="product-list transition border-l fixed">
<div class="suggest-header">
<h2>Produits associés</h2>
<span class="close-btn"></span>
......@@ -233,72 +391,5 @@ $subcat_iD = $product_cats[1]->term_id;
<h3 class = "font-small" >Distributeur pour <br> serviettes pliage décalè</h3>
</article>
</div>
</div>
</div>
</div>
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo htmlspecialchars( wp_json_encode( $available_variations ) ) ?>">
<?php do_action( 'woocommerce_before_variations_form' ); ?>
<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
<p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
<?php else : ?>
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<td class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( stripslashes( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . esc_html__( 'Clear', 'woocommerce' ) . '</a>' ) : '';
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<div class="single_variation_wrap">
<?php
/**
* woocommerce_before_single_variation Hook.
*/
do_action( 'woocommerce_before_single_variation' );
/**
* woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
* @since 2.4.0
* @hooked woocommerce_single_variation - 10 Empty div for variation data.
* @hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
/**
* woocommerce_after_single_variation Hook.
*/
//do_action( 'woocommerce_after_single_variation' );
?>
</div>
<?php //do_action( 'woocommerce_after_add_to_cart_button' ); ?>
<?php endif; ?>
<?php //do_action( 'woocommerce_after_variations_form' ); ?>
</form>
<a href="<?php echo get_permalink(43);?>" class="hidden download_file_link"></a>
<a href="#" class="download_file">Télécharger la fiche technique </a>
<?php
//do_action( 'woocommerce_after_add_to_cart_form' );
?>
</div>
......@@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
global $product;
?>
<div class="product_meta">
<!--<div class="product_meta">
<?php do_action( 'woocommerce_product_meta_start' ); ?>
......@@ -38,4 +38,4 @@ global $product;
<?php do_action( 'woocommerce_product_meta_end' ); ?>
</div>
</div>-->
......@@ -30,7 +30,7 @@ $tabs = apply_filters( 'woocommerce_product_tabs', array() );
if ( ! empty( $tabs ) ) : ?>
<div class="woocommerce-tabs wc-tabs-wrapper">
<!--<div class="woocommerce-tabs wc-tabs-wrapper">
<ul class="tabs wc-tabs" role="tablist">
<?php foreach ( $tabs as $key => $tab ) : ?>
<li class="<?php echo esc_attr( $key ); ?>_tab" id="tab-title-<?php echo esc_attr( $key ); ?>" role="tab" aria-controls="tab-<?php echo esc_attr( $key ); ?>">
......@@ -43,6 +43,6 @@ if ( ! empty( $tabs ) ) : ?>
<?php call_user_func( $tab['callback'], $key, $tab ); ?>
</div>
<?php endforeach; ?>
</div>
</div>-->
<?php endif; ?>
......@@ -20,4 +20,4 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
the_title( '<h1 class="product_title entry-title">', '</h1>' );
//the_title( '<h1 class="product_title entry-title">', '</h1>' );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment