| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin View: Quick Edit Product. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Quick edit visibility select template. |
| 14 |
* |
| 15 |
* @var array $options |
| 16 |
*/ |
| 17 |
?> |
| 18 |
|
| 19 |
<fieldset class="inline-edit-col-left"> |
| 20 |
<div class="inline-edit-col"> |
| 21 |
<div class="inline-edit-group"> |
| 22 |
<label class="inline-edit-status alignleft"> |
| 23 |
<span class="title"><?php /* translators: Product POS visibility or barcode label in WooCommerce admin. */ esc_html_e( 'POS visibility', 'woocommerce-pos' ); ?></span> |
| 24 |
<select name="_pos_visibility"> |
| 25 |
<?php |
| 26 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template variables. |
| 27 |
foreach ( $options as $name => $label ) { |
| 28 |
echo '<option value="' . esc_attr( $name ) . '">' . esc_html( $label ) . '</option>'; |
| 29 |
} |
| 30 |
?> |
| 31 |
</select> |
| 32 |
</label> |
| 33 |
</div> |
| 34 |
</div> |
| 35 |
<script> |
| 36 |
document.addEventListener('DOMContentLoaded', function() { |
| 37 |
// we create a copy of the WP inline edit post function |
| 38 |
const wp_inline_edit = window.inlineEditPost.edit; |
| 39 |
|
| 40 |
// and then we overwrite the function with our own code |
| 41 |
window.inlineEditPost.edit = function (id) { |
| 42 |
// "call" the original WP edit function |
| 43 |
// we don't want to leave WordPress hanging |
| 44 |
wp_inline_edit.apply(this, arguments); |
| 45 |
|
| 46 |
// now we take care of our business |
| 47 |
|
| 48 |
// get the post ID |
| 49 |
let post_id = 0; |
| 50 |
if (typeof id === 'object') { |
| 51 |
post_id = parseInt(this.getId(id), 10); |
| 52 |
} |
| 53 |
|
| 54 |
if (post_id > 0) { |
| 55 |
// define the edit row |
| 56 |
const edit_row = document.getElementById('edit-' + post_id); |
| 57 |
|
| 58 |
// get the data |
| 59 |
let val = ''; |
| 60 |
let elem = document.getElementById('woocommerce_pos_inline_' + post_id); |
| 61 |
if (elem) { |
| 62 |
val = elem.dataset.visibility; |
| 63 |
} |
| 64 |
|
| 65 |
// populate the data |
| 66 |
const select = edit_row.querySelector('select[name="_pos_visibility"]'); |
| 67 |
if (select) { |
| 68 |
select.value = val; |
| 69 |
} |
| 70 |
} |
| 71 |
}; |
| 72 |
}); |
| 73 |
</script> |
| 74 |
</fieldset> |
| 75 |
|