| 1 |
<?php namespace TierPricingTable\Addons\AdvancedQuantityOptions; |
| 2 |
|
| 3 |
use TierPricingTable\Forms\Form; |
| 4 |
|
| 5 |
class AdvancedQuantityOptionsForm { |
| 6 |
|
| 7 |
public function __construct() { |
| 8 |
add_action( 'admin_head', array( $this, 'includeAssets' ) ); |
| 9 |
} |
| 10 |
|
| 11 |
public function includeAssets() { |
| 12 |
?> |
| 13 |
<style> |
| 14 |
.tiered_pricing_advanced_quantity_options { |
| 15 |
overflow: hidden; |
| 16 |
} |
| 17 |
|
| 18 |
.tiered_pricing_advanced_quantity_options__toggle-advanced-options { |
| 19 |
padding-left: 163px; |
| 20 |
font-size: 12px; |
| 21 |
margin-bottom: 10px; |
| 22 |
} |
| 23 |
|
| 24 |
.tiered_pricing_advanced_quantity_options__toggle-advanced-options a { |
| 25 |
text-decoration: none; |
| 26 |
} |
| 27 |
|
| 28 |
/* Icon */ |
| 29 |
.tiered_pricing_advanced_quantity_options__toggle-advanced-options a span { |
| 30 |
font-size: 12px; |
| 31 |
line-height: 11px; |
| 32 |
height: 12px; |
| 33 |
width: 12px; |
| 34 |
vertical-align: middle; |
| 35 |
transition: all .1s; |
| 36 |
} |
| 37 |
|
| 38 |
.tiered_pricing_advanced_quantity_options__toggle-advanced-options--open a span { |
| 39 |
transform: rotate(180deg); |
| 40 |
line-height: 14px; |
| 41 |
} |
| 42 |
|
| 43 |
.tiered_pricing_advanced_quantity_options__advanced-options { |
| 44 |
overflow: hidden; |
| 45 |
display: none; |
| 46 |
position: relative; |
| 47 |
} |
| 48 |
|
| 49 |
.tiered_pricing_advanced_quantity_options__advanced-options--visible { |
| 50 |
display: block; |
| 51 |
} |
| 52 |
|
| 53 |
/* Variations adjustment */ |
| 54 |
.variable_pricing .tiered_pricing_advanced_quantity_options__advanced-options input { |
| 55 |
margin-top: 6px; |
| 56 |
} |
| 57 |
|
| 58 |
.variable_pricing .tiered_pricing_advanced_quantity_options__toggle-advanced-options { |
| 59 |
padding-left: 0; |
| 60 |
} |
| 61 |
</style> |
| 62 |
<script> |
| 63 |
jQuery(document).ready(function ($) { |
| 64 |
jQuery(document).on('click', '.tiered_pricing_advanced_quantity_options__toggle-advanced-options > a', function (e) { |
| 65 |
e.preventDefault(); |
| 66 |
$(this).parent().toggleClass('tiered_pricing_advanced_quantity_options__toggle-advanced-options--open'); |
| 67 |
$(this).closest('.tiered_pricing_advanced_quantity_options').find('.tiered_pricing_advanced_quantity_options__advanced-options').toggleClass('tiered_pricing_advanced_quantity_options__advanced-options--visible') |
| 68 |
}); |
| 69 |
}); |
| 70 |
</script> |
| 71 |
<?php |
| 72 |
} |
| 73 |
|
| 74 |
public function render( $productId, $loop = null, $role = null, $expandedByDefault = false, $showToggle = true ) { |
| 75 |
|
| 76 |
$maximumFieldName = Form::getFieldName( AdvancedQuantityOptionsAddon::MAXIMUM_QUANTITY_BASE_META_KEY, $role, |
| 77 |
$loop ); |
| 78 |
$groupOfFieldName = Form::getFieldName( AdvancedQuantityOptionsAddon::GROUP_OF_QUANTITY_BASE_META_KEY, $role, |
| 79 |
$loop ); |
| 80 |
?> |
| 81 |
|
| 82 |
<div class="tiered_pricing_advanced_quantity_options"> |
| 83 |
<?php |
| 84 |
|
| 85 |
$maximum = DataProvider::getMaximumQuantity( $productId, $role, 'edit' ); |
| 86 |
$groupOf = DataProvider::getGroupOfQuantity( $productId, $role, 'edit' ); |
| 87 |
|
| 88 |
$isVisible = $maximum || $groupOf || $expandedByDefault; |
| 89 |
|
| 90 |
$maximumFieldAttributes = array( |
| 91 |
'min' => 2, |
| 92 |
'step' => 1, |
| 93 |
); |
| 94 |
|
| 95 |
$groupOfFieldAttributes = array( |
| 96 |
'min' => 2, |
| 97 |
'step' => 1, |
| 98 |
); |
| 99 |
|
| 100 |
if ( ! tpt_fs()->can_use_premium_code() ) { |
| 101 |
$maximumFieldAttributes['disabled'] = true; |
| 102 |
$groupOfFieldAttributes['disabled'] = true; |
| 103 |
} |
| 104 |
?> |
| 105 |
|
| 106 |
<?php if ( $showToggle ) : ?> |
| 107 |
<div |
| 108 |
class="tiered_pricing_advanced_quantity_options__toggle-advanced-options <?php echo esc_attr( $isVisible ? 'tiered_pricing_advanced_quantity_options__toggle-advanced-options--open' : '' ); ?>"> |
| 109 |
<a href="#" role="button"> |
| 110 |
<?php |
| 111 |
esc_html_e( 'Additional quantity options', 'tier-pricing-table' ); |
| 112 |
?> |
| 113 |
<span class="dashicons dashicons-arrow-down-alt2"></span> |
| 114 |
</a> |
| 115 |
</div> |
| 116 |
<?php endif; ?> |
| 117 |
|
| 118 |
<div |
| 119 |
class="tiered_pricing_advanced_quantity_options__advanced-options |
| 120 |
<?php echo esc_attr( $isVisible ? 'tiered_pricing_advanced_quantity_options__advanced-options--visible' : '' ); ?> |
| 121 |
<?php echo esc_attr( ! is_null( $loop ) ? 'form-row' : '' ); ?> |
| 122 |
"> |
| 123 |
<?php |
| 124 |
woocommerce_wp_text_input( array( |
| 125 |
'id' => $maximumFieldName, |
| 126 |
'name' => $maximumFieldName, |
| 127 |
'type' => 'number', |
| 128 |
'custom_attributes' => $maximumFieldAttributes, |
| 129 |
'style' => tpt_fs()->can_use_premium_code() ? '' : 'cursor: not-allowed;', |
| 130 |
'value' => $maximum, |
| 131 |
'placeholder' => __( 'Leave blank for no restrictions', |
| 132 |
'tier-pricing-table' ), |
| 133 |
'label' => __( 'Maximum order quantity', 'tier-pricing-table' ), |
| 134 |
'description' => __( 'The maximum quantity of the product a customer can order in a single transaction.', |
| 135 |
'tier-pricing-table' ), |
| 136 |
'desc_tip' => true, |
| 137 |
) ); |
| 138 |
|
| 139 |
woocommerce_wp_text_input( array( |
| 140 |
'id' => $groupOfFieldName, |
| 141 |
'name' => $groupOfFieldName, |
| 142 |
'type' => 'number', |
| 143 |
'custom_attributes' => $groupOfFieldAttributes, |
| 144 |
'style' => tpt_fs()->can_use_premium_code() ? '' : 'cursor: not-allowed;', |
| 145 |
'value' => $groupOf, |
| 146 |
'label' => __( 'Quantity step', 'tier-pricing-table' ), |
| 147 |
'placeholder' => __( 'Leave blank for no restrictions', |
| 148 |
'tier-pricing-table' ), |
| 149 |
'description' => __( 'Requires the product to be purchased in multiples of X.', |
| 150 |
'tier-pricing-table' ), |
| 151 |
'desc_tip' => true, |
| 152 |
) ); |
| 153 |
?> |
| 154 |
</div> |
| 155 |
|
| 156 |
</div> |
| 157 |
<?php |
| 158 |
} |
| 159 |
} |