Skip to content

Commit

Permalink
refactor(Product Fields): Added filter to let toggle the mandate of p…
Browse files Browse the repository at this point in the history
…roduct fields

New filter hook '[3~ns_mandate_product_fields added'
  • Loading branch information
mayeenulislam committed Mar 29, 2018
1 parent a9a9bee commit 1db0127
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
27 changes: 25 additions & 2 deletions includes/ns-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,31 @@ function ns_handle_registration_login_ticket_submission() {
// Ticket Product & Receipt
$NSECommerce = new NSECommerce();
if( $NSECommerce->ecommerce_enabled() ) {
$ticket_product = ! empty($_POST['ns_ticket_product']) ? $_POST['ns_ticket_product'] : '';
$ticket_receipt = ! empty($_POST['ns_ticket_product_receipt']) ? $_POST['ns_ticket_product_receipt'] : '';

/**
* -----------------------------------------------------------------------
* HOOK : FILTER HOOK
* ns_mandate_product_fields
*
* Hook to moderate the permission for mandating product-specifc fields,
* or not.
*
* @since 1.0.0
* -----------------------------------------------------------------------
*/
$mandate_product_fields = apply_filters( 'ns_mandate_product_fields', true );

if( $mandate_product_fields && empty($_POST['ns_ticket_product']) ) {
$ns_errors[] = esc_html__( 'Adding Product relevent to the ticket is mandatory', 'nanosupport' );
} else {
$ticket_product = ! empty($_POST['ns_ticket_product']) ? $_POST['ns_ticket_product'] : '';
}

if( $mandate_product_fields && empty($_POST['ns_ticket_product_receipt']) ) {
$ns_errors[] = esc_html__( 'Product Receipt must be mentioned for further enquiry', 'nanosupport' );
} else {
$ticket_receipt = ! empty($_POST['ns_ticket_product_receipt']) ? $_POST['ns_ticket_product_receipt'] : '';
}
}


Expand Down
23 changes: 19 additions & 4 deletions includes/shortcodes/ns-submit-ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,33 @@ function ns_submit_support_ticket() {
$NSECommerce = new NSECommerce();
if( $NSECommerce->ecommerce_enabled() ) {
$products = $NSECommerce->get_products();

/**
* -----------------------------------------------------------------------
* HOOK : FILTER HOOK
* ns_mandate_product_fields
*
* Hook to moderate the permission for mandating product-specifc fields,
* or not.
*
* @since 1.0.0
* -----------------------------------------------------------------------
*/
$mandate_product_fields = apply_filters( 'ns_mandate_product_fields', true );
?>

<!-- TICKET PRODUCTS -->
<div class="ns-form-group">
<label for="ns-ticket-product" class="ns-col-md-2 ns-col-sm-2 ns-col-xs-10 ns-control-label">
<?php esc_html_e( 'Product', 'nanosupport' ); ?> <sup class="ns-required">*</sup>
<?php esc_html_e( 'Product', 'nanosupport' ); ?>
<?php if( $mandate_product_fields ) echo '<sup class="ns-required">*</sup>'; ?>
</label>
<div class="ns-col-md-1 ns-col-sm-1 ns-col-xs-2 ns-text-center">
<?php echo ns_tooltip( 'ns-product', esc_html__( 'Select the product the ticket is about.', 'nanosupport' ), 'bottom' ); ?>
</div>
<div class="ns-col-md-9 ns-col-sm-9 ns-col-xs-12 ns-form-inline">
<?php $submit_val = !empty($_POST['ns_ticket_product']) ? $_POST['ns_ticket_product'] : ''; ?>
<select class="ns-form-control" name="ns_ticket_product" id="ns-ticket-product" aria-describedby="ns-product" required>
<select class="ns-form-control" name="ns_ticket_product" id="ns-ticket-product" aria-describedby="ns-product" <?php if( $mandate_product_fields ) echo 'required'; ?>>
<option value="" <?php selected( $submit_val, '' ); ?>><?php esc_html_e( 'Select a product', 'nanosupport' ); ?></option>
<?php foreach($products as $id => $product_name) { ?>
<option value="<?php echo $id; ?>" <?php selected( $submit_val, $id ); ?>>
Expand All @@ -285,14 +299,15 @@ function ns_submit_support_ticket() {
<!-- TICKET PRODUCT RECEIPT -->
<div class="ns-form-group">
<label for="ns-ticket-receipt" class="ns-col-md-2 ns-col-sm-2 ns-col-xs-10 ns-control-label">
<?php esc_html_e( 'Purhcase Receipt', 'nanosupport' ); ?> <sup class="ns-required">*</sup>
<?php esc_html_e( 'Purhcase Receipt', 'nanosupport' ); ?>
<?php if( $mandate_product_fields ) echo '<sup class="ns-required">*</sup>'; ?>
</label>
<div class="ns-col-md-1 ns-col-sm-1 ns-col-xs-2 ns-text-center">
<?php echo ns_tooltip( 'ns-product-receipt', esc_html__( 'Enter the receipt number of purchasing the product.', 'nanosupport' ), 'bottom' ); ?>
</div>
<div class="ns-col-md-9 ns-col-sm-9 ns-col-xs-12 ns-form-inline">
<?php $submit_val = !empty($_POST['ns_ticket_product_receipt']) ? $_POST['ns_ticket_product_receipt'] : ''; ?>
<input type="number" name="ns_ticket_product_receipt" class="ns-form-control" id="ns-ticket-product-receipt" aria-describedby="ns-product-receipt" value="<?php echo $submit_val; ?>" min="0" required>
<input type="number" name="ns_ticket_product_receipt" class="ns-form-control" id="ns-ticket-product-receipt" aria-describedby="ns-product-receipt" value="<?php echo $submit_val; ?>" min="0" <?php if( $mandate_product_fields ) echo 'required'; ?>>
</div>
</div> <!-- /.ns-form-group -->

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Or, you can use software like [POEdit](https://poedit.net/download) ('cross-plat
= 0.5.0 - 2018-MAR-30 =
* New Feature: E-commerce &mdash; Support to products of Easy Digital Downloads (v2.5+) and WooCommerce (v2.2+)
* 7 new icons to NanoSupport Icons
* New filter hook: 'ns_date_time_format'
* New filter hooks: 'ns_date_time_format', 'ns_mandate_product_fields'

= 0.4.1 - 2017-JUL-23 =
* Bug fixed: Ticket additional info was affecting on show/hide in smaller devices
Expand Down

0 comments on commit 1db0127

Please sign in to comment.