Last active
August 29, 2015 14:10
-
-
Save ChuckMac/910f4250c26737bb4694 to your computer and use it in GitHub Desktop.
Create WooCommerce Coupon Automagically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_coupon_code', 'create_coupon' ); | |
function create_coupon ( $coupon ) { | |
if ( '' != $coupon ) { | |
//$the_coupon = new WC_Coupon( $coupon ); | |
if ( ! $the_coupon->id ) { | |
$coupon_data = array( | |
'post_title' => $coupon, | |
'post_content' => '', | |
'post_status' => 'publish', | |
'post_author' => 1, | |
'post_type' => 'shop_coupon' | |
); | |
$coupon_id = wp_insert_post( $coupon_data ); | |
update_post_meta( $coupon_id, 'discount_type', 'percent_product' ); | |
update_post_meta( $coupon_id, 'coupon_amount', '50' ); | |
} | |
} | |
return $coupon; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment