LLMS_Meta_Box_Coupon::save( int $post_id )
Save all metadata
Description Description
Parameters Parameters
- $post_id
-
(int) (Required) post_id of the post we're editing
Return Return
(void)
Source Source
File: includes/admin/post-types/meta-boxes/class.llms.meta.box.coupon.php
protected function save( $post_id ) { $c = new LLMS_Coupon( $post_id ); // dupcheck the title $exists = llms_find_coupon( $c->get( 'title' ), $post_id ); if ( $exists ) { $this->add_error( __( 'Coupon code already exists. Customers will use the most recently created coupon with this code.', 'lifterlms' ) ); } // trial validation $trial = isset( $_POST[ $this->prefix . 'enable_trial_discount' ] ) ? $_POST[ $this->prefix . 'enable_trial_discount' ] : false; if ( ! $trial ) { $_POST[ $this->prefix . 'enable_trial_discount' ] = 'no'; } elseif ( 'yes' === $trial && empty( $_POST[ $this->prefix . 'trial_amount' ] ) ) { $this->add_error( __( 'A Trial Discount Amount was not supplied. Trial Pricing Discount has automatically been disabled. Please re-enable Trial Pricing Discount and enter a Trial Discount Amount, then save this coupon again.', 'lifterlms' ) ); $_POST[ $this->prefix . 'enable_trial_discount' ] = 'no'; } if ( ! isset( $_POST[ $this->prefix . 'coupon_courses' ] ) ) { $_POST[ $this->prefix . 'coupon_courses' ] = array(); } if ( ! isset( $_POST[ $this->prefix . 'coupon_membership' ] ) ) { $_POST[ $this->prefix . 'coupon_membership' ] = array(); } // save all the fields $fields = array( 'coupon_amount', 'trial_amount', 'usage_limit', 'coupon_courses', 'coupon_membership', 'enable_trial_discount', 'discount_type', 'description', 'expiration_date', 'plan_type', ); foreach ( $fields as $field ) { if ( isset( $_POST[ $this->prefix . $field ] ) ) { $c->set( $field, $_POST[ $this->prefix . $field ] ); } } }
Expand full source code Collapse full source code View on GitHub