Skip to content

Instantly share code, notes, and snippets.

@Spreeuw
Created February 26, 2020 19:47
Show Gist options
  • Save Spreeuw/e3b5d78fbea0c225b64b6d6f3fcea879 to your computer and use it in GitHub Desktop.
Save Spreeuw/e3b5d78fbea0c225b64b6d6f3fcea879 to your computer and use it in GitHub Desktop.
<?php
add_action('woocommerce_order_item_add_action_buttons','wpo_bulk_edit_line_item_prices',10,1);
function wpo_bulk_edit_line_item_prices($order) {
?>
<input type="text" class="bulk-multiply-items-multiplier" size="5" style="float:left;"><button type="button" class="button bulk-multiply-items">multiply prices</button>
<script>
jQuery(function($) {
$('.button.bulk-multiply-items').click(function(event){
event.preventDefault();
var multiplier = parseFloat( $('.bulk-multiply-items-multiplier').val() );
$('.edit-order-item').each(function(){
var type = $(this).closest('tbody').attr('id');
if (type == 'order_line_items' || type == 'order_shipping_line_items') {
$(this).trigger('click'); // enable edit mode
if (type == 'order_line_items') {
$line_subtotal = $(this).closest('tr').find('td.line_cost input.line_subtotal');
$line_subtotal.val(parseFloat($line_subtotal.val())*multiplier);
}
$line_total = $(this).closest('tr').find('td.line_cost input.line_total');
$line_total.val(parseFloat($line_total.val())*multiplier);
}
});
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment