Skip to content

Coupon creation via code should check for duplicates #2219

@mihaijoldis

Description

@mihaijoldis

When you generate a coupon from the code directly perhaps we should check for duplicates ?

<?php
		$coup_creation = date( 'Y-m-d')  . " 00:00:00";
		$coup_expiration = date( 'Y-m-d', strtotime( '+1 month' ) ). " 23:59:59";
		
		$new_coupon = new WPSC_Coupon( array(
			'coupon_code'   => 'd1e1d1d12d212d', // d1e1d1d12d212d
			'value'         => '20',
			'is-percentage' => true, // true for %
			'use-once'      => true,
			'is-used'       => 0,
			'active'        => true,
			'every_product' => false,
			'start'         => $coup_creation,
			'expiry'        => $coup_expiration,
			'condition'     => array()
		) );
		
		$insert = $new_coupon->save();

If you run the code you will get multiple coupons with the same name

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions