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