Passed
Pull Request — master (#126)
by Kiran
03:46
created

admin-meta-boxes.php ➔ wpinv_discount_metabox_details()   F

Complexity

Conditions 13
Paths 1024

Size

Total Lines 212
Code Lines 140

Duplication

Lines 30
Ratio 14.15 %

Importance

Changes 0
Metric Value
cc 13
eloc 140
nc 1024
nop 1
dl 30
loc 212
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
// MUST have WordPress.
3
if ( !defined( 'WPINC' ) ) {
4
    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
5
}
6
7
function wpinv_add_meta_boxes( $post_type, $post ) {
8
    global $wpi_mb_invoice;
9
    if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) {
10
        $wpi_mb_invoice = wpinv_get_invoice( $post->ID );
11
    }
12
    
13
    if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) {
14
        add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' );
15
    }
16
    
17
    if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) {
18
        add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' );
19
    }
20
    
21
    if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
0 ignored issues
show
Documentation introduced by
$wpi_mb_invoice is of type object<WPInv_Invoice>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
22
        add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' );
23
    }
24
    
25
    add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' );
26
    add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' );
27
   
28
    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
29
    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30
    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
31
}
32
add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
33
34
function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $update is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    remove_action( 'save_post', __FUNCTION__ );
36
    
37
    // $post_id and $post are required
38
    if ( empty( $post_id ) || empty( $post ) ) {
39
        return;
40
    }
41
        
42
    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
43
        return;
44
    }
45
    
46
    // Dont' save meta boxes for revisions or autosaves
47
    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
48
        return;
49
    }
50
        
51
    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
52
        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
53
            return;
54
        }
55
    
56
        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
57
            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
58
        }
59
    } else if ( $post->post_type == 'wpi_item' ) {
60
        // verify nonce
61
        if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
62
            $fields                                 = array();
63
            $fields['_wpinv_price']              = 'wpinv_item_price';
64
            $fields['_wpinv_vat_class']          = 'wpinv_vat_class';
65
            $fields['_wpinv_vat_rule']           = 'wpinv_vat_rules';
66
            $fields['_wpinv_type']               = 'wpinv_item_type';
67
            $fields['_wpinv_is_recurring']       = 'wpinv_is_recurring';
68
            $fields['_wpinv_recurring_period']   = 'wpinv_recurring_period';
69
            $fields['_wpinv_recurring_interval'] = 'wpinv_recurring_interval';
70
            $fields['_wpinv_recurring_limit']    = 'wpinv_recurring_limit';
71
            $fields['_wpinv_free_trial']         = 'wpinv_free_trial';
72
            $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73
            $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74
            
75
            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
76
                $_POST['wpinv_is_recurring'] = 0;
77
            }
78
            
79
            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
80
                $_POST['wpinv_free_trial'] = 0;
81
            }
82
            
83
            foreach ( $fields as $field => $name ) {
84
                if ( isset( $_POST[ $name ] ) ) {
85
                    $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id );
86
87
                    if ( !$allowed ) {
88
                        continue;
89
                    }
90
91
                    if ( $field == '_wpinv_price' ) {
92
                        $value = wpinv_sanitize_amount( $_POST[ $name ] );
93
                    } else {
94
                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
95
                    }
96
                    
97
                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
98
                    update_post_meta( $post_id, $field, $value );
99
                }
100
            }
101
            
102
            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
103
                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
104
            }
105
        }
106
    }
107
}
108
add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
109
110
function wpinv_register_item_meta_boxes() {    
111
    global $wpinv_euvat;
112
    
113
    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
114
115
    if ( $wpinv_euvat->allow_vat_rules() ) {
116
        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
117
    }
118
    
119
    if ( $wpinv_euvat->allow_vat_classes() ) {
120
        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
121
    }
122
    
123
    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
124
    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
125
}
126
127
function wpinv_register_discount_meta_boxes() {
128
    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
129
}
130
131
function wpinv_discount_metabox_details( $post ) {
132
    $discount_id    = $post->ID;
133
    $discount       = wpinv_get_discount( $discount_id );
0 ignored issues
show
Unused Code introduced by
$discount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
134
    
135
    $type               = wpinv_get_discount_type( $discount_id );
136
    $item_reqs          = wpinv_get_discount_item_reqs( $discount_id );
137
    $excluded_items     = wpinv_get_discount_excluded_items( $discount_id );
138
    $min_total          = wpinv_get_discount_min_total( $discount_id );
139
    $max_total          = wpinv_get_discount_max_total( $discount_id );
140
    $max_uses           = wpinv_get_discount_max_uses( $discount_id );
141
    $single_use         = wpinv_discount_is_single_use( $discount_id );
142
    $recurring          = (bool)wpinv_discount_is_recurring( $discount_id );
143
    $start_date         = wpinv_get_discount_start_date( $discount_id );
144
    $expiration_date    = wpinv_get_discount_expiration( $discount_id );
145
    
146 View Code Duplication
    if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) {
147
        $start_time         = strtotime( $start_date );
148
        $start_h            = date_i18n( 'H', $start_time );
149
        $start_m            = date_i18n( 'i', $start_time );
150
        $start_date         = date_i18n( 'Y-m-d', $start_time );
151
    } else {
152
        $start_h            = '00';
153
        $start_m            = '00';
154
    }
155
156 View Code Duplication
    if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) {
157
        $expiration_time    = strtotime( $expiration_date );
158
        $expiration_h       = date_i18n( 'H', $expiration_time );
159
        $expiration_m       = date_i18n( 'i', $expiration_time );
160
        $expiration_date    = date_i18n( 'Y-m-d', $expiration_time );
161
    } else {
162
        $expiration_h       = '23';
163
        $expiration_m       = '59';
164
    }
165
    
166
    $min_total          = $min_total > 0 ? $min_total : '';
167
    $max_total          = $max_total > 0 ? $max_total : '';
168
    $max_uses           = $max_uses > 0 ? $max_uses : '';
169
?>
170
<?php do_action( 'wpinv_discount_form_top', $post ); ?>
171
<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
172
<table class="form-table wpi-form-table">
173
    <tbody>
174
        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
175
        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
176
        <tr>
177
            <th valign="top" scope="row">
178
                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
179
            </th>
180
            <td>
181
                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
182
                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
183
            </td>
184
        </tr>
185
        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
186
        <tr>
187
            <th valign="top" scope="row">
188
                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
189
            </th>
190
            <td>
191
                <select id="wpinv_discount_type" name="type" class="medium-text">
192
                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
193
                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
194
                    <?php } ?>
195
                </select>
196
                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
197
            </td>
198
        </tr>
199
        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
200
        <tr>
201
            <th valign="top" scope="row">
202
                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
203
            </th>
204
            <td>
205
                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font>
206
                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
207
                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
208
            </td>
209
        </tr>
210
        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
211
        <tr>
212
            <th valign="top" scope="row">
213
                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
214
            </th>
215
            <td>
216
                <p><?php echo wpinv_item_dropdown( array(
217
                        'name'              => 'items[]',
218
                        'id'                => 'items',
219
                        'selected'          => $item_reqs,
220
                        'multiple'          => true,
221
                        'class'             => 'medium-text',
222
                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
223
                        'show_recurring'    => true,
224
                    ) ); ?>
225
                </p>
226
                <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p>
227
            </td>
228
        </tr>
229
        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
230
        <tr>
231
            <th valign="top" scope="row">
232
                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
233
            </th>
234
            <td>
235
                <p><?php echo wpinv_item_dropdown( array(
236
                        'name'              => 'excluded_items[]',
237
                        'id'                => 'excluded_items',
238
                        'selected'          => $excluded_items,
239
                        'multiple'          => true,
240
                        'class'             => 'medium-text',
241
                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
242
                        'show_recurring'    => true,
243
                    ) ); ?>
244
                </p>
245
                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
246
            </td>
247
        </tr>
248
        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
249
        <tr>
250
            <th valign="top" scope="row">
251
                <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label>
252
            </th>
253
            <td>
254
                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h">
255 View Code Duplication
                    <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
256
                    <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option>
257
                    <?php } ?>
258
                </select> : <select id="wpinv_discount_start_m" name="start_m">
259 View Code Duplication
                    <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
260
                    <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option>
261
                    <?php } ?>
262
                </select>
263
                <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p>
264
            </td>
265
        </tr>
266
        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
267
        <tr>
268
            <th valign="top" scope="row">
269
                <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label>
270
            </th>
271
            <td>
272
                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h">
273 View Code Duplication
                    <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
274
                    <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option>
275
                    <?php } ?>
276
                </select> : <select id="wpinv_discount_expiration_m" name="expiration_m">
277 View Code Duplication
                    <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
278
                    <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option>
279
                    <?php } ?>
280
                </select>
281
                <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p>
282
            </td>
283
        </tr>
284
        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
285
        <tr>
286
            <th valign="top" scope="row">
287
                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
288
            </th>
289
            <td>
290
                <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
291
                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
292
            </td>
293
        </tr>
294
        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
295
        <tr>
296
            <th valign="top" scope="row">
297
                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
298
            </th>
299
            <td>
300
                <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
301
                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
302
            </td>
303
        </tr>
304
        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
305
        <tr>
306
            <th valign="top" scope="row">
307
                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
308
            </th>
309
            <td>
310
                <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
311
                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
312
                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
313
                </select>
314
                <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p>
315
            </td>
316
        </tr>
317
        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
318
        <tr>
319
            <th valign="top" scope="row">
320
                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
321
            </th>
322
            <td>
323
                <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
324
                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
325
            </td>
326
        </tr>
327
        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
328
        <tr>
329
            <th valign="top" scope="row">
330
                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
331
            </th>
332
            <td>
333
                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
334
                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
335
            </td>
336
        </tr>
337
        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
338
    </tbody>
339
</table>
340
<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
341
    <?php
342
}
343
344
function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
345
    $post_type = !empty( $post ) ? $post->post_type : '';
346
    
347
    if ( $post_type != 'wpi_discount' ) {
348
        return;
349
    }
350
    
351
    if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) {
352
        return;
353
    }
354
    
355
    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
356
        return;
357
    }
358
    
359
    if ( !current_user_can( 'manage_options', $post_id ) ) {
360
        return;
361
    }
362
    
363
    if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) {
364
        $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m'];
365
    }
366
367
    if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) {
368
        $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m'];
369
    }
370
    
371
    return wpinv_store_discount( $post_id, $_POST, $post, $update );
372
}
373
add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );