Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created August 27, 2012 20:25
Show Gist options
  • Select an option

  • Save wpsmith/3491973 to your computer and use it in GitHub Desktop.

Select an option

Save wpsmith/3491973 to your computer and use it in GitHub Desktop.
Creates a Shopp Promotion
/**
* Creates a Shopp Promotion.
*
* $defaults = array(
* // Enable the promo
* 'status' => 'enabled',
*
* // DATES
* 'starts' => array(
* 'month' => '',
* 'date' => '',
* 'year' => '',
* ),
* 'ends' => array(
* 'month' => '',
* 'date' => '',
* 'year' => '',
* ),
*
* // DISCOUNT
* 'type' => 'Percentage Off',
* //Options: Percentage Off,
* Amount Off,
* Free Shipping,
* Buy X Get Y Free (target must be Cart Item)
* 'discount' => '',
* 'buyqty' => '',
* 'getqty' => '',
*
* // CONDITIONS
* 'search' => 'any', //Options: any, all
* 'target' => 'Catalog', //Options: Catalog, Cart, Cart Item
* 'rules' => array(),
* 'property' => '',
* if ( Catalog == target ):
* Options: Name,
* Category,
* Variation,
* Price,
* Sales Price,
* Type,
* In Stock
* if ( Cart == target ):
* Options: Any item name,
* Any item quantity,
* Any item amount,
* Total quantity,
* Shipping amount,
* Subtotal amount,
* Discount amount,
* Customer type,
* Ship-to country,
* Promo use count,
* Promo code,
*
* 'logic' => '',
* ['rules'][#]['property'] = Name, Category, Variation
* Options: Is equal to,
* Is not equal to,
* Contains,
* Does not contain,
* Begins with,
* Ends with
* ['rules'][#]['property'] = Price, Sales Price, In Stock
* Options: Is equal to,
* Is not equal to,
* Is greater than,
* Is greater than or equal to,
* Is less than,
* Is less than or equal to
* ['rules'][#]['property'] = Type
* Options: Is equal to,
* Is not equal to,
* 'value' => '',
*
* 'item' => array(
* array( 'property' => '', 'logic' => '', 'value' => '', ),
* ),
* 'property' => '',
* Options: Name,
* Category,
* Tag name,
* Variation,
* Input name,
* Input Value,
* Quantity,
* Unit price,
* Total price,
* Discount amount
* 'logic' => '',
['rules']['item'][#]['property'] = Name, Category, Tag name, Variation, Input name, Input Value
* Options: Is equal to,
* Is not equal to,
* Contains,
* Does not contain,
* Begins with,
* Ends with
*
['rules']['item'][#]['property'] = Unit price, Total price, Discount amount
* Options: Is equal to,
* Is not equal to,
* Is greater than,
* Is greater than or equal to,
* Is less than,
* Is less than or equal to
* 'value' => '',
*
* );
*
* @author Travis Smith
* @since 1.3.0
* @param string $name (required) Name of the Promotion
* @param array $args (required) Array of arguments needed to create Promo
*/
function shopp_create_promo( $name, $args = array() ) {
$defaults = array(
// Status
'status' => false,
'starts' => array(
'month' => '',
'date' => '',
'year' => '',
),
'ends' => array(
'month' => '',
'date' => '',
'year' => '',
),
// Discount
'type' => 'Percentage Off',
// Conditions
'search' => 'any',
'target' => 'Catalog',
);
$args = wp_parse_args( $args, $defaults );
// Create Promotion Object
$Promotion = new Promotion();
// Setup Promotion Object
$Promotion->name = $name;
$Promotion->uses = 0;
$Promotion->created = null;
$Promotion->modified = null;
$Promotion->status = isset( $args['status'] ) ? $args['status'] : '';
// Update/Save Promotion Object
$Promotion->updates( $args );
$Promotion->save();
do_action_ref_array('shopp_promo_saved',array(&$Promotion));
return $Promotion;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment