| 1 |
<?php if ( ! defined( 'WPINC' ) ) { |
| 2 |
die; |
| 3 |
} |
| 4 |
|
| 5 |
/** |
| 6 |
* Available variables |
| 7 |
* |
| 8 |
* @var array $rules |
| 9 |
*/ |
| 10 |
|
| 11 |
$prefix = 'category'; |
| 12 |
|
| 13 |
?> |
| 14 |
|
| 15 |
<tr class="form-field"> |
| 16 |
<th scope="row" valign="top"> |
| 17 |
<label for="attribute_label">Tiered pricing</label> |
| 18 |
</th> |
| 19 |
<td> |
| 20 |
|
| 21 |
<style> |
| 22 |
.tpt-category-tiered-pricing-rule { |
| 23 |
display: flex; |
| 24 |
margin-bottom: 15px; |
| 25 |
gap: 10px; |
| 26 |
} |
| 27 |
|
| 28 |
.tpt-category-tiered-pricing-rule__quantity input, .tpt-category-tiered-pricing-rule__discount input { |
| 29 |
width: 170px !important; |
| 30 |
} |
| 31 |
|
| 32 |
.tpt-category-tiered-pricing-add-new { |
| 33 |
margin-top: 15px; |
| 34 |
margin-bottom: 15px; |
| 35 |
} |
| 36 |
|
| 37 |
.remove-price-rule { |
| 38 |
display: inline-block; |
| 39 |
position: relative; |
| 40 |
padding: 2px 0 2px 5px; |
| 41 |
outline: none; |
| 42 |
cursor: pointer; |
| 43 |
} |
| 44 |
</style> |
| 45 |
|
| 46 |
<div class="tpt-category-tiered-pricing"> |
| 47 |
<div class="tpt-category-tiered-pricing-rules"> |
| 48 |
<div class="tpt-category-tiered-pricing-rule"> |
| 49 |
<div class="tpt-category-tiered-pricing-rule__quantity"> |
| 50 |
<input type="number" style="margin-right: 10px;" min="2" |
| 51 |
placeholder="<?php esc_attr_e( 'Quantity', 'tier-pricing-table' ); ?>" |
| 52 |
class="price-quantity-rule price-quantity-rule--simple" |
| 53 |
name="tiered_price_percent_quantity_<?php echo esc_attr($prefix); ?>[]"> |
| 54 |
</div> |
| 55 |
<div class="tpt-category-tiered-pricing-rule__discount"> |
| 56 |
<input type="number" max="99" |
| 57 |
placeholder="<?php esc_attr_e( 'Percentage discount', 'tier-pricing-table' ); ?>" |
| 58 |
class="price-quantity-rule--simple" |
| 59 |
name="tiered_price_percent_discount_<?php echo esc_attr($prefix); ?>[]" |
| 60 |
step="any" min="0"> |
| 61 |
</div> |
| 62 |
<div class="tpt-category-tiered-pricing-rule__remove"> |
| 63 |
<span class="notice-dismiss remove-price-rule"> |
| 64 |
</div> |
| 65 |
</div> |
| 66 |
</div> |
| 67 |
<div class="tpt-category-tiered-pricing-add-new"> |
| 68 |
<button class="button"> |
| 69 |
<?php esc_html_e( 'New tier', 'tier-pricing-table' ); ?> |
| 70 |
</button> |
| 71 |
</div> |
| 72 |
</div> |
| 73 |
|
| 74 |
<p class="description"> |
| 75 |
<?php |
| 76 |
esc_attr_e( 'Assign percentage discounts for products that have this category. Rules can be overridden |
| 77 |
in product.', 'tier-pricing-table' ); |
| 78 |
?> |
| 79 |
<?php echo wc_help_tip( 'if you are not using this feature you can disable this functionality in the settings to do not complicate the interface' ); ?> |
| 80 |
</p> |
| 81 |
<br> |
| 82 |
</td> |
| 83 |
</tr> |
| 84 |
|
| 85 |
<script> |
| 86 |
jQuery('.tpt-category-tiered-pricing-add-new').click(function (e) { |
| 87 |
var $rules = jQuery(e.target).closest('.tpt-category-tiered-pricing').find('.tpt-category-tiered-pricing-rules'); |
| 88 |
|
| 89 |
var $rule = $rules.find('.tpt-category-tiered-pricing-rule').first().clone(); |
| 90 |
|
| 91 |
$rule.find('input').val(''); |
| 92 |
|
| 93 |
$rules.append($rule); |
| 94 |
}); |
| 95 |
|
| 96 |
jQuery('body').on('click', '.tpt-category-tiered-pricing-rule__remove', function (e) { |
| 97 |
|
| 98 |
e.preventDefault(); |
| 99 |
|
| 100 |
var $rule = jQuery(e.target).closest('.tpt-category-tiered-pricing-rule'); |
| 101 |
|
| 102 |
var $rules = jQuery(e.target).closest('.tpt-category-tiered-pricing-rules'); |
| 103 |
|
| 104 |
if ($rules.find('.tpt-category-tiered-pricing-rule').length < 2) { |
| 105 |
$rule.find('input').val(''); |
| 106 |
} else { |
| 107 |
$rule.remove(); |
| 108 |
} |
| 109 |
}); |
| 110 |
</script> |