You appear to be a bot. Output may be restricted
Description
Create a new discount. If the discount already exists in the database, update it.
Usage
$mixed = EDD_Discount::add( $args );
Parameters
- $args
- ( array ) required – Discount details.
Returns
mixed bool|int false if data isn't passed and class not instantiated for creation, or post ID for the new discount.
Source
File name: easy-digital-downloads/includes/class-edd-discount.php
Lines:
1 to 74 of 74
public function add( $args ) { // If no code is provided, return early with false if ( empty( $args['code'] ) ) { return false; } $meta = $this->build_meta( $args ); if ( ! empty( $this->ID ) && $this->exists() ) { return $this->update( $args ); } else { /** * Add a new discount to the database. */ /** * Filters the metadata before being inserted into the database. * * @since 2.7 * * @param array $meta Discount meta. * @param int $ID Discount ID. */ $meta = apply_filters( 'edd_insert_discount', $meta ); /** * Fires before the discount has been added to the database. * * @since 2.7 * * @param array $meta Discount meta. */ do_action( 'edd_pre_insert_discount', $meta ); $this->ID = wp_insert_post( array( 'post_type' => 'edd_discount', 'post_title' => $meta['name'], 'post_status' => 'active' ) ); foreach ( $meta as $key => $value ) { $this->update_meta( $key, $value ); } /** * Fires after the discount code is inserted. * * @param array $meta { * The discount details. * * @type string $code The discount code. * @type string $name The name of the discount. * @type string $status The discount status. Defaults to active. * @type int $uses The current number of uses. * @type int $max_uses The max number of uses. * @type string $start The start date. * @type int $min_price The minimum price required to use the discount code. * @type array $product_reqs The product IDs required to use the discount code. * @type string $product_condition The conditions in which a product(s) must meet to use the discount code. * @type array $excluded_products Product IDs excluded from this discount code. * @type bool $is_not_global If the discount code is not globally applied to all products. Defaults to false. * @type bool $is_single_use If the code cannot be used more than once per customer. Defaults to false. * } * @param int $ID The ID of the discount that was inserted. */ do_action( 'edd_post_insert_discount', $meta, $this->ID ); $this->setup_discount( WP_Post::get_instance( $this->ID ) ); // Discount code created return $this->ID; } }