2

WooCommerce にクーポンをまとめて追加する方法を探していました。実際には、割引を提供する 800 のメンバーシップ番号のリストであり、クーポンはこれを行うための最良の方法のようです。

プログラムで 1 つのクーポンを追加する方法を見つけました: http://docs.woothemes.com/document/create-a-coupon-programatically/しかし、限られた PHP の知識では、800 を追加するには十分ではないようです。

配列または何らかの形で.csvにリンクすると推測していますが、よくわかりません。どんな助けにも感謝します。

4

1 に答える 1

3

800 個の異なるキーの配列を作成し、foreach ループを作成して、このように配列にある異なるキーごとにプロセスを繰り返すことができます

forehach ( $your_800_array as $coupon_code){
 //the code from the page you posted
 $amount = '10'; // Amount
 $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
 $coupon = array(
 'post_title' => $coupon_code,
 'post_content' => '',
 'post_status' => 'publish',
 'post_author' => 1,
 'post_type' => 'shop_coupon'
 );
 $new_coupon_id = wp_insert_post( $coupon );
 // Add meta
 update_post_meta( $new_coupon_id, 'discount_type', $discount_type );
 update_post_meta( $new_coupon_id, 'coupon_amount', $amount );
 update_post_meta( $new_coupon_id, 'individual_use', 'no' );
 update_post_meta( $new_coupon_id, 'product_ids', '' );
 update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );
 update_post_meta( $new_coupon_id, 'usage_limit', '' );
 update_post_meta( $new_coupon_id, 'expiry_date', '' );
 update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' );
 update_post_meta( $new_coupon_id, 'free_shipping', 'no' );
}

(OPがループ内に投稿したコードを使用しました。実際にはテストされていません)

于 2014-11-18T03:52:20.757 に答える