You appear to be a bot. Output may be restricted
Description
Build the base of the discount.
Usage
$int|bool = EDD_Discount::insert_discount();
Parameters
Returns
int|bool Discount ID or false on error.
Source
File name: easy-digital-downloads/includes/class-edd-discount.php
Lines:
1 to 72 of 72
private function insert_discount() { $discount_data = array( 'code' => isset( $this->code ) ? $this->code : '', 'name' => isset( $this->name ) ? $this->name : '', 'status' => isset( $this->status ) ? $this->status : 'active', 'uses' => isset( $this->uses ) ? $this->uses : '', 'max_uses' => isset( $this->max_uses ) ? $this->max_uses : '', 'amount' => isset( $this->amount ) ? $this->amount : '', 'start' => isset( $this->start ) ? $this->start : '', 'expiration' => isset( $this->expiration ) ? $this->expiration : '', 'type' => isset( $this->type ) ? $this->type : '', 'min_price' => isset( $this->min_price ) ? $this->min_price : '', 'product_reqs' => isset( $this->product_reqs ) ? $this->product_reqs : array(), 'product_condition' => isset( $this->product_condition ) ? $this->product_condition : '', 'excluded_products' => isset( $this->excluded_products ) ? $this->excluded_products : array(), 'is_not_global' => isset( $this->is_not_global ) ? $this->is_not_global : false, 'is_single_use' => isset( $this->is_single_use ) ? $this->is_single_use : false, ); $start_timestamp = strtotime( $discount_data['start'] ); if ( ! empty( $discount_data['start'] ) ) { $discount_data['start'] = date( 'm/d/Y H:i:s', $start_timestamp ); } if ( ! empty( $discount_data['expiration'] ) ) { $discount_data['expiration'] = date( 'm/d/Y H:i:s', strtotime( date( 'm/d/Y', strtotime( $discount_data['expiration'] ) ) . ' 23:59:59' ) ); $end_timestamp = strtotime( $discount_data['expiration'] ); if ( ! empty( $discount_data['start'] ) && $start_timestamp > $end_timestamp ) { // Set the expiration date to the start date if start is later than expiration $discount_data['expiration'] = $discount_data['start']; } } if ( ! empty( $discount_data['excluded_products'] ) ) { foreach ( $discount_data['excluded_products'] as $key => $product ) { if ( 0 === intval( $product ) ) { unset( $discount_data['excluded_products'][ $key ] ); } } } $args = apply_filters( 'edd_insert_discount_args', array( 'post_title' => $this->name, 'post_status' => $discount_data['status'], 'post_type' => 'edd_discount', 'post_date' => ! empty( $this->date ) ? $this->date : null, 'post_date_gmt' => ! empty( $this->date ) ? get_gmt_from_date( $this->date ) : null ), $discount_data ); // Create a blank edd_discount post $discount_id = wp_insert_post( $args ); if ( ! empty( $discount_id ) ) { $this->ID = $discount_id; foreach ( $discount_data as $key => $value ) { if( ! empty( $value ) ) { $this->update_meta( $key, $value ); } } } return $this->ID; }