Snippets

Martin Urbánek Woocommerce

Created by Martin Urbánek
<?php
/*
* Funkce přidá tlačítko pro přiřazení stejné ceny všem variacím
*
*   https://www.gowp.com/blog/apply-the-price-of-a-woocommerce-product-variation-to-all-variations-of-the-same-product/
*/

add_action( 'woocommerce_product_data_panels', 'gowp_global_variation_price' );
function gowp_global_variation_price() {
	global $woocommerce;
	?>
		<script type="text/javascript">
			function addVariationLinks() {
				a = jQuery( '<a href="#">Apply to all Variations</a>' );
				b = jQuery( 'input[name^="variable_regular_price"]' );
				a.click( function( c ) {
					d = jQuery( this ).parent( 'label' ).next( 'input[name^="variable_regular_price"]' ).val();
					e = confirm( "Change the price of all variations to " + d + "?" );
					if ( e ) b.val( d ).trigger( 'change' );
					c.preventDefault();
				} );
				b.prev( 'label' ).append( " " ).append( a );
			}
			<?php if ( version_compare( $woocommerce->version, '2.4', '>=' ) ) : ?>
				jQuery( document ).ready( function() {
					jQuery( document ).ajaxComplete( function( event, request, settings ) {
						if ( settings.data.lastIndexOf( "action=woocommerce_load_variations", 0 ) === 0 ) {
							addVariationLinks();
						}
					} );
				} );
			<?php else: ?>
				addVariationLinks();
			<?php endif; ?>
		</script>
	<?php
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.