public function enqueue($hook) { global $post, $woocommerce; if ($hook == 'woocommerce_page_wc_dynamic_pricing' || $post && $post->post_type == 'product') { if (floatval($woocommerce->version) >= 2.0) { wp_enqueue_style('woocommerce-pricing-admin', WC_Dynamic_Pricing::plugin_url() . '/assets/admin/admin.css'); wp_enqueue_script('woocommerce-pricing-admin', WC_Dynamic_Pricing::plugin_url() . '/assets/admin/admin.js', array('jquery', 'jquery-ui-datepicker')); } else { wp_enqueue_style('woocommerce-pricing-admin', WC_Dynamic_Pricing::plugin_url() . '/assets/legacy/admin/admin.css'); wp_enqueue_script('woocommerce-pricing-admin', WC_Dynamic_Pricing::plugin_url() . '/assets/legacy/admin/admin.js', array('jquery')); } wp_localize_script('woocommerce-pricing-admin', 'woocommerce_pricing_admin', array('calendar_image' => $woocommerce->plugin_url() . '/assets/images/calendar.png')); // Enqueue jQuery UI styles $jquery_version = isset($wp_scripts->registered['jquery-ui-core']->ver) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2'; wp_enqueue_style('jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/' . $jquery_version . '/themes/smoothness/jquery-ui.css'); } }
private function meta_box_javascript() { ?> <script type="text/javascript"> jQuery(document).ready(function ($) { <?php do_action('woocommerce_dynamic_pricing_metabox_js', 'advanced_category'); ?> var set_index = 0; var rule_indexes = new Array(); $('.woocommerce_pricing_ruleset').each(function () { var length = $('table tbody tr', $(this)).length; if (length == 1) { $('.delete_pricing_rule', $(this)).hide(); } }); $("#woocommerce-pricing-add-ruleset").click(function (event) { event.preventDefault(); var set_index = $("#woocommerce-pricing-rules-wrap").data('setindex') + 1; $("#woocommerce-pricing-rules-wrap").data('setindex', set_index); var data = { set_index: set_index, post:<?php echo isset($_GET['post']) ? $_GET['post'] : 0; ?> , action: 'create_empty_category_ruleset' } $.post(ajaxurl, data, function (response) { $('#woocommerce-pricing-rules-wrap').append(response); }); }); $('#woocommerce-pricing-rules-wrap').delegate('.pricing_rule_apply_to', 'change', function (event) { var value = $(this).val(); if (value != 'roles' && $('.roles', $(this).parent()).is(':visible')) { $('.roles', $(this).parent()).fadeOut(); $('.roles input[type=checkbox]', $(this).closest('div')).removeAttr('checked'); } if (value == 'roles') { $('.roles', $(this).parent()).fadeIn(); } }); $('#woocommerce-pricing-rules-wrap').delegate('.pricing_rule_mode', 'change', function (event) { var value = $(this).val(); if (value != 'block') { $('table.block', $(this).closest('div.woocommerce_pricing_ruleset')).parent().fadeOut('fast', function () { $('table.continuous', $(this).closest('div.woocommerce_pricing_ruleset')).parent().fadeIn(); }); } else { $('table.continuous', $(this).closest('div.woocommerce_pricing_ruleset')).parent().fadeOut('fast', function () { $('table.block', $(this).closest('div.woocommerce_pricing_ruleset')).parent().fadeIn(); }); } }); //Remove Pricing Set $('#woocommerce-pricing-rules-wrap').delegate('.delete_pricing_ruleset', 'click', function (event) { event.preventDefault(); DeleteRuleSet($(this).data('name')); return false; }); //Add Button $('#woocommerce-pricing-rules-wrap').delegate('.add_pricing_rule', 'click', function (event) { event.preventDefault(); InsertContinuousRule($(this).data('index'), $(this).data('name')); }); $('#woocommerce-pricing-rules-wrap').delegate('.add_pricing_blockrule', 'click', function (event) { event.preventDefault(); InsertBlockRule($(this).data('index'), $(this).data('name')); }); //Remove Button $('#woocommerce-pricing-rules-wrap').delegate('.delete_pricing_rule', 'click', function (event) { event.preventDefault(); DeleteRule($(this).data('index'), $(this).data('name')); }); //Remove Button $('#woocommerce-pricing-rules-wrap').delegate('.delete_pricing_blockrule', 'click', function (event) { event.preventDefault(); DeleteBlockRule($(this).closest('tr'), $(this).closest('table')); }); $("#woocommerce-pricing-rules-wrap").sortable( { handle: 'h4.first', containment: 'parent', axis: 'y' }); function InsertContinuousRule(previousRowIndex, name) { var $index = $("#woocommerce-pricing-rules-table-" + name).data('lastindex') + 1; $("#woocommerce-pricing-rules-table-" + name).data('lastindex', $index); var html = ''; html += '<tr id="pricing_rule_row_' + name + '_' + $index + '">'; html += '<td>'; html += '<input class="int_pricing_rule" id="pricing_rule_from_input_' + name + '_' + $index + '" type="text" name="pricing_rules[' + name + '][rules][' + $index + '][from]" value="" /> '; html += '</td>'; html += '<td>'; html += '<input class="int_pricing_rule" id="pricing_rule_to_input_' + name + '_' + $index + '" type="text" name="pricing_rules[' + name + '][rules][' + $index + '][to]" value="" /> '; html += '</td>'; html += '<td>'; html += '<select id="pricing_rule_type_value_' + name + '_' + $index + '" name="pricing_rules[' + name + '][rules][' + $index + '][type]">'; html += '<option value="price_discount">Price Discount</option>'; html += '<option value="percentage_discount">Percentage Discount</option>'; html += '<option value="fixed_price">Fixed Price</option>'; html += '</select>'; html += '</td>'; html += '<td>'; html += '<input class="float_pricing_rule" id="pricing_rule_amount_input_' + $index + '" type="text" name="pricing_rules[' + name + '][rules][' + $index + '][amount]" value="" /> '; html += '</td>'; html += '<td>'; html += '<a data-index="' + $index + '" data-name="' + name + '" class="add_pricing_rule"><img src="<?php echo WC_Dynamic_Pricing::plugin_url() . '/assets/images/add.png'; ?> " title="add another rule" alt="add another rule" style="cursor:pointer; margin:0 3px;" /></a>'; html += '<a data-index="' + $index + '" data-name="' + name + '" class="delete_pricing_rule"><img data-index="' + $index + '" src="<?php echo WC_Dynamic_Pricing::plugin_url() . '/assets/images/remove.png'; ?> " title="remove rule" alt="remove rule" style="cursor:pointer; margin:0 3px;" /></a>'; html += '</td>'; html += '</tr>'; $('#pricing_rule_row_' + name + '_' + previousRowIndex).after(html); $('.delete_pricing_rule', "#woocommerce-pricing-rules-table-" + name).show(); } function InsertBlockRule(previousRowIndex, name) { var $index = $("#woocommerce-pricing-blockrules-table-" + name).data('lastindex') + 1; $("#woocommerce-pricing-blockrules-table-" + name).data('lastindex', $index); var html = ''; html += '<tr id="pricing_blockrule_row_' + name + '_' + $index + '">'; html += '<td>'; html += '<input class="int_pricing_blockrule" type="text" name="pricing_rules[' + name + '][blockrules][' + $index + '][from]" value="" /> '; html += '</td>'; html += '<td>'; html += '<input class="int_pricing_blockrule" type="text" name="pricing_rules[' + name + '][blockrules][' + $index + '][to]" value="" /> '; html += '</td>'; html += '<td>'; html += '<select name="pricing_rules[' + name + '][blockrules][' + $index + '][type]">'; html += '<option value="price_discount">Price Discount</option>'; html += '<option value="percentage_discount">Percentage Discount</option>'; html += '<option value="fixed_price">Fixed Price</option>'; html += '</select>'; html += '</td>'; html += '<td>'; html += '<input class="float_pricing_rule" id="pricing_rule_amount_input_' + $index + '" type="text" name="pricing_rules[' + name + '][blockrules][' + $index + '][amount]" value="" /> '; html += '</td>'; html += '<td>'; html += '<select name="pricing_rules[' + name + '][blockrules][' + $index + '][repeating]">'; html += '<option value="no">No</option>'; html += '<option value="yes">Yes</option>'; html += '</select>'; html += '</td>'; html += '<td width="48">'; html += '<a data-index="' + $index + '" data-name="' + name + '" class="add_pricing_blockrule"><img src="<?php echo WC_Dynamic_Pricing::plugin_url() . '/assets/images/add.png'; ?> " title="add another rule" alt="add another rule" style="cursor:pointer; margin:0 3px;" /></a>'; html += '<a data-index="' + $index + '" data-name="' + name + '" class="delete_pricing_blockrule"><img data-index="' + $index + '" src="<?php echo WC_Dynamic_Pricing::plugin_url() . '/assets/images/remove.png'; ?> " title="remove rule" alt="remove rule" style="cursor:pointer; margin:0 3px;" /></a>'; html += '</td>'; html += '</tr>'; $('#pricing_blockrule_row_' + name + '_' + previousRowIndex).after(html); $('.delete_pricing_blockrule', "#woocommerce-pricing-blockrules-table-" + name).show(); } function DeleteRule(index, name) { if (confirm("Are you sure you would like to remove this price adjustment?")) { $('#pricing_rule_row_' + name + '_' + index).remove(); var $index = $('tbody tr', "#woocommerce-pricing-rules-table-" + name).length; if ($index > 1) { $('.delete_pricing_rule', "#woocommerce-pricing-rules-table-" + name).show(); } else { $('.delete_pricing_rule', "#woocommerce-pricing-rules-table-" + name).hide(); } } } function DeleteBlockRule($tr, $table) { if (confirm("Are you sure you would like to remove this price adjustment?")) { $tr.remove(); var count = $('tr', $table).length; if (count > 1) { $('.delete_pricing_blockrule', $table).show(); } else { $('.delete_pricing_blockrule', $table).hide(); } } } function DeleteRuleSet(name) { if (confirm('Are you sure you would like to remove this dynamic price set?')) { $('#woocommerce-pricing-ruleset-' + name).slideUp().remove(); } return false; } }); </script> <?php }
private function meta_box_javascript() { ?> <script type="text/javascript"> jQuery(document).ready(function ($) { <?php do_action('woocommerce_dynamic_pricing_metabox_js', 'advanced_totals'); ?> var set_index = 0; var rule_indexes = new Array(); $('.woocommerce_pricing_ruleset').each(function () { var length = $('table tbody tr', $(this)).length; if (length == 1) { $('.delete_pricing_rule', $(this)).hide(); } }); $("#woocommerce-pricing-add-ruleset").click(function (event) { event.preventDefault(); var set_index = $("#woocommerce-pricing-rules-wrap").data('setindex') + 1; $("#woocommerce-pricing-rules-wrap").data('setindex', set_index); var data = { set_index: set_index, post:<?php echo isset($_GET['post']) ? $_GET['post'] : 0; ?> , action: 'create_empty_totals_ruleset' } $.post(ajaxurl, data, function (response) { $('#woocommerce-pricing-rules-wrap').append(response); }); }); $('#woocommerce-pricing-rules-wrap').delegate('.pricing_rule_apply_to', 'change', function (event) { var value = $(this).val(); if (value != 'roles') { $('.roles', $(this).parent()).fadeOut(); $('.roles input[type=checkbox]', $(this).closest('div')).removeAttr('checked'); } else { $('.roles', $(this).parent()).fadeIn(); } }); $('#woocommerce-pricing-rules-wrap').delegate('.pricing_rule_when', 'change', function (event) { var value = $(this).val(); if (value != 'cat') { $('.cats', $(this).closest('div')).fadeOut(); $('.cats input[type=checkbox]', $(this).closest('div')).removeAttr('checked'); } else { $('.cats', $(this).closest('div')).fadeIn(); } }); //Remove Pricing Set $('#woocommerce-pricing-rules-wrap').delegate('.delete_pricing_ruleset', 'click', function (event) { event.preventDefault(); DeleteRuleSet($(this).data('name')); }); //Add Button $('#woocommerce-pricing-rules-wrap').delegate('.add_pricing_rule', 'click', function (event) { event.preventDefault(); InsertRule($(this).data('index'), $(this).data('name')); }); //Remove Button $('#woocommerce-pricing-rules-wrap').delegate('.delete_pricing_rule', 'click', function (event) { event.preventDefault(); DeleteRule($(this).data('index'), $(this).data('name')); }); //Validation $('#woocommerce-pricing-rules-wrap').delegate('.int_pricing_rule', 'keydown', function (event) { // Allow only backspace, delete and tab if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 190) { // let it happen, don't do anything } else { if (event.shiftKey && event.keyCode == 56) { if ($(this).val().length > 0) { event.preventDefault(); } else { return true; } } else if (event.shiftKey) { event.preventDefault(); } else if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) { event.preventDefault(); } else { if ($(this).val() == "*") { event.preventDefault(); } } } }); $('#woocommerce-pricing-rules-wrap').delegate('.float_pricing_rule', 'keydown', function (event) { // Allow only backspace, delete and tab if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 190) { // let it happen, don't do anything } else { // Ensure that it is a number and stop the keypress if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) { event.preventDefault(); } } }); $("#woocommerce-pricing-rules-wrap").sortable( { handle: 'h4.first', containment: 'parent', axis: 'y' }); function InsertRule(previousRowIndex, name) { var $index = $("#woocommerce-pricing-rules-table-" + name).data('lastindex') + 1; $("#woocommerce-pricing-rules-table-" + name).data('lastindex', $index); var html = ''; html += '<tr id="pricing_rule_row_' + name + '_' + $index + '">'; html += '<td>'; html += '<input class="int_pricing_rule" id="pricing_rule_from_input_' + name + '_' + $index + '" type="text" name="pricing_rules[' + name + '][rules][' + $index + '][from]" value="" /> '; html += '</td>'; html += '<td>'; html += '<input class="int_pricing_rule" id="pricing_rule_to_input_' + name + '_' + $index + '" type="text" name="pricing_rules[' + name + '][rules][' + $index + '][to]" value="" /> '; html += '</td>'; html += '<td>'; html += '<select id="pricing_rule_type_value_' + name + '_' + $index + '" name="pricing_rules[' + name + '][rules][' + $index + '][type]">'; html += '<option value="percentage_discount">Percentage Discount</option>'; html += '</select>'; html += '</td>'; html += '<td>'; html += '<input class="float_pricing_rule" id="pricing_rule_amount_input_' + $index + '" type="text" name="pricing_rules[' + name + '][rules][' + $index + '][amount]" value="" /> '; html += '</td>'; html += '<td>'; html += '<a data-index="' + $index + '" data-name="' + name + '" class="add_pricing_rule"><img src="<?php echo WC_Dynamic_Pricing::plugin_url() . '/assets/images/add.png'; ?> " title="add another rule" alt="add another rule" style="cursor:pointer; margin:0 3px;" /></a>'; html += '<a data-index="' + $index + '" data-name="' + name + '" class="delete_pricing_rule"><img data-index="' + $index + '" src="<?php echo WC_Dynamic_Pricing::plugin_url() . '/assets/images/remove.png'; ?> " title="remove rule" alt="remove rule" style="cursor:pointer; margin:0 3px;" /></a>'; html += '</td>'; html += '</tr>'; $('#pricing_rule_row_' + name + '_' + previousRowIndex).after(html); $('.delete_pricing_rule', "#woocommerce-pricing-rules-table-" + name).show(); } function DeleteRule(index, name) { if (confirm("Are you sure you would like to remove this price adjustment?")) { $('#pricing_rule_row_' + name + '_' + index).remove(); var $index = $('tbody tr', "#woocommerce-pricing-rules-table-" + name).length; if ($index > 1) { $('.delete_pricing_rule', "#woocommerce-pricing-rules-table-" + name).show(); } else { $('.delete_pricing_rule', "#woocommerce-pricing-rules-table-" + name).hide(); } } } function DeleteRuleSet(name) { if (confirm('Are you sure you would like to remove this dynamic price set?')) { $('#woocommerce-pricing-ruleset-' + name).slideUp().remove(); } } }); </script> <?php }