| 1 |
<?php |
| 2 |
/** |
| 3 |
* Product metabox |
| 4 |
* |
| 5 |
* @package SeQura/WC |
| 6 |
* @var string $args The arguments. Must contain keys: |
| 7 |
* - 'is_banned' The is_banned value (bool). |
| 8 |
* - 'is_banned_field_name' The name of the field to store the is_banned value (string). |
| 9 |
* - 'enabled_for_services' The enabled_for_services value (bool). |
| 10 |
* - 'is_service' The is_service value (bool). |
| 11 |
* - 'is_not_service_field_name' The name of the field to store the is_service value (string). |
| 12 |
* - 'allow_payment_delay' The allow_payment_delay value (bool). |
| 13 |
* - 'service_end_date' The service_end_date value (string). |
| 14 |
* - 'service_end_date_field_name' The name of the field to store the service_end_date value (string). |
| 15 |
*/ |
| 16 |
|
| 17 |
defined( 'WPINC' ) || die; |
| 18 |
if ( ! isset( |
| 19 |
$args['is_banned'], |
| 20 |
$args['is_banned_field_name'], |
| 21 |
$args['enabled_for_services'], |
| 22 |
$args['is_service'], |
| 23 |
$args['is_service_field_name'], |
| 24 |
$args['service_end_date'], |
| 25 |
$args['service_end_date_default'], |
| 26 |
$args['service_end_date_field_name'], |
| 27 |
$args['allow_payment_delay'], |
| 28 |
$args['service_desired_first_charge_date'], |
| 29 |
$args['service_desired_first_charge_date_field_name'], |
| 30 |
$args['date_or_duration_regex'], |
| 31 |
$args['allow_registration_items'], |
| 32 |
$args['service_registration_amount'], |
| 33 |
$args['service_registration_amount_field_name'], |
| 34 |
$args['nonce_name'] |
| 35 |
) ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
wp_nonce_field( -1, $args['nonce_name'] ); |
| 40 |
?> |
| 41 |
<div class="wc-metaboxes-wrapper"> |
| 42 |
<div id="sequra_settings_is_banned" style="padding: 6px 0 8px;"> |
| 43 |
<input id="is_sequra_banned" name="<?php echo esc_attr( $args['is_banned_field_name'] ); ?>" type="checkbox" value="yes" <?php echo ( (bool) $args['is_banned'] ) ? 'checked' : ''; ?>/> |
| 44 |
<label for="is_sequra_banned"> |
| 45 |
<?php esc_html_e( 'Do not offer seQura for this product', 'sequra' ); ?> |
| 46 |
</label> |
| 47 |
</div> |
| 48 |
<?php |
| 49 |
if ( ( (bool) $args['enabled_for_services'] ) ) : |
| 50 |
?> |
| 51 |
<div id="sequra_service_is_service" style="padding: 6px 0 8px;"> |
| 52 |
<input id="is_sequra_service" name="<?php echo esc_attr( $args['is_service_field_name'] ); ?>" type="checkbox" value="no" <?php echo ! ( (bool) $args['is_service'] ) ? 'checked' : ''; ?>/> |
| 53 |
<label for="is_sequra_service"> |
| 54 |
<?php esc_html_e( 'This is not a service', 'sequra' ); ?> |
| 55 |
</label> |
| 56 |
</div> |
| 57 |
<div id="sequra_service_service_options"> |
| 58 |
<!-- Service end date --> |
| 59 |
<div style="padding: 6px 0 8px;display:grid;gap:4px"> |
| 60 |
<label for="sequra_service_end_date"><?php esc_html_e( 'Service end date', 'sequra' ); ?></label> |
| 61 |
<input id="sequra_service_end_date" name="<?php echo esc_attr( $args['service_end_date_field_name'] ); ?>" type="text" value="<?php echo esc_attr( $args['service_end_date'] ); ?>" placeholder="<?php echo esc_attr( $args['service_end_date_default'] ); ?>" pattern="<?php echo esc_attr( $args['date_or_duration_regex'] ); ?>" /> |
| 62 |
<small><?php esc_html_e( 'Date i.e: 2021-06-06 or period i.e: P1Y for 1 year', 'sequra' ); ?></small> |
| 63 |
</div> |
| 64 |
<?php if ( (bool) $args['allow_payment_delay'] ) : ?> |
| 65 |
<!-- Service desired first charge date --> |
| 66 |
<div style="padding: 6px 0 8px;display:grid;gap:4px"> |
| 67 |
<label for="sequra_desired_first_charge_date"><?php esc_html_e( 'First instalment delay or date', 'sequra' ); ?></label> |
| 68 |
<input id="sequra_desired_first_charge_date" name="<?php echo esc_attr( $args['service_desired_first_charge_date_field_name'] ); ?>" type="text" value="<?php echo esc_attr( $args['service_desired_first_charge_date'] ); ?>" placeholder="<?php esc_attr_e( 'date or period in ISO8601 format', 'sequra' ); ?>" pattern="<?php echo esc_attr( $args['date_or_duration_regex'] ); ?>" /> |
| 69 |
<small><?php esc_html_e( 'Date i.e: 2021-01-01 or period i.e: P1M for 1 month', 'sequra' ); ?></small> |
| 70 |
</div> |
| 71 |
<?php endif; ?> |
| 72 |
<?php if ( (bool) $args['allow_registration_items'] ) : ?> |
| 73 |
<!-- Service registration amount --> |
| 74 |
<div style="padding: 6px 0 8px;display:grid;gap:4px"> |
| 75 |
<label for="sequra_registration_amount"><?php esc_html_e( 'Registration amount', 'sequra' ); ?> (€)</label> |
| 76 |
<input id="sequra_registration_amount" name="<?php echo esc_attr( $args['service_registration_amount_field_name'] ); ?>" type="number" value="<?php echo esc_attr( $args['service_registration_amount'] ); ?>" step="0.01" /> |
| 77 |
<small><?php esc_html_e( 'Part of the price that will be paid as registration fee', 'sequra' ); ?></small> |
| 78 |
</div> |
| 79 |
<?php endif; ?> |
| 80 |
</div> |
| 81 |
<script> |
| 82 |
(function(){ |
| 83 |
const toggleServiceFields = function() { |
| 84 |
const checkbox = document.querySelector('#is_sequra_service'); |
| 85 |
document.querySelector('#sequra_service_service_options').style.display = checkbox.checked ? 'none' : 'block'; |
| 86 |
document.querySelector('#sequra_service_end_date').disabled = checkbox.checked; |
| 87 |
document.querySelector('#sequra_desired_first_charge_date').disabled = checkbox.checked; |
| 88 |
document.querySelector('#sequra_registration_amount').disabled = checkbox.checked; |
| 89 |
}; |
| 90 |
document.querySelector('#is_sequra_service').addEventListener('change', toggleServiceFields); |
| 91 |
toggleServiceFields(); |
| 92 |
})(); |
| 93 |
</script> |
| 94 |
<?php endif; ?> |
| 95 |
</div> |