set_name( $name ); $product->set_regular_price( $price ); $product->set_category_ids( array( $category ) ); $product->set_catalog_visibility( 'visible' ); $product->set_stock_status( 'instock' ); return $product->save(); } $discounted = wc_edm_ci_category( 'CI Discounted' ); $other = wc_edm_ci_category( 'CI Other' ); $product_in = wc_edm_ci_product( 'CI product in group', 100, $discounted ); $product_out = wc_edm_ci_product( 'CI product outside group', 50, $other ); $group_id = WC_EDM_DB::insert_group( array( 'name' => 'CI Group', 'discount_percent' => 20, ) ); WC_EDM_DB::set_group_categories( $group_id, array( $discounted ) ); $coupon = new WC_Coupon(); $coupon->set_code( 'ciflat10' ); $coupon->set_discount_type( 'fixed_cart' ); $coupon->set_amount( 10 ); $coupon->save(); /** * Insert an email assignment, filling in the columns the caller did not name. * * @param array $data Partial assignment row. * @return int */ function wc_edm_ci_assign( $data ) { return WC_EDM_DB::insert_email( array_merge( array( 'assignment_type' => 'group', 'group_id' => null, 'coupon_code' => null, 'custom_discount' => null, 'is_active' => 1, 'free_shipping' => 0, ), $data ) ); } // The three pattern kinds, arranged so that priority is observable: // exact@company.com is matched by BOTH the exact rule and the domain rule, and // "partial" is contained in partialperson@elsewhere.test. wc_edm_ci_assign( array( 'email_pattern' => '@company.com', 'assignment_type' => 'group', 'group_id' => $group_id, ) ); wc_edm_ci_assign( array( 'email_pattern' => 'exact@company.com', 'assignment_type' => 'custom', 'custom_discount' => 50, ) ); wc_edm_ci_assign( array( 'email_pattern' => 'partial', 'assignment_type' => 'custom', 'custom_discount' => 5, ) ); wc_edm_ci_assign( array( 'email_pattern' => 'buyer@coupons.test', 'assignment_type' => 'coupon', 'coupon_code' => 'ciflat10', ) ); wc_edm_ci_assign( array( 'email_pattern' => 'switched-off@company.dk', 'assignment_type' => 'custom', 'custom_discount' => 90, 'is_active' => 0, ) ); update_option( 'wc_edm_ci_fixtures', array( 'group_id' => $group_id, 'category' => $discounted, 'product_in' => $product_in, 'product_out' => $product_out, ) ); printf( " fixtures: group #%d (20%%) on category #%d, products #%d (100) and #%d (50), 5 assignments, coupon ciflat10\n", $group_id, $discounted, $product_in, $product_out );