autoship_generate_virtual_wc_coupon (function)

( src/coupons.php) Used to generate a new WooCommerce Virtual Coupon given supplied data. Takes $coupon_data as its parameter and returns a new WooCommerce Virtual Coupon.

Function: 

/**
 * Generates a virtual WC Coupon using the supplied data.
 *
 * @param array $coupon_data The data to use for creating the coupon
 * @return WC_Coupon The virtual coupon.
 */
function autoship_generate_virtual_wc_coupon( $coupon_data ){

  $args = wp_parse_args( $coupon_data, array(
    'code'          => '',
    'description'   => '',
    'discount_type' => '',
    'amount'        => 0
  ) );

  $coupon = new WC_Coupon();
  $coupon->set_code( $args['code'] );
  $coupon->set_description( $args['description'] );
  $coupon->set_discount_type( $args['discount_type'] );
  $coupon->set_amount( $args['amount'] );
  $coupon->set_virtual( true );

  return apply_filters( 'autoship_generated_virtual_wc_coupon', $coupon, $coupon_data );

}