2013-07-22 70 views
2

我一直在尋找一種將優惠券批量添加到WooCommerce的方式,它實際上是800個會員號碼的列表,授予折扣,優惠券似乎是實現此目的的最佳方式。以編程方式在WooCommerce中創建多個優惠券

我已經找到一種方法來添加一臺優惠券編程:http://docs.woothemes.com/document/create-a-coupon-programatically/但我有限的知識PHP似乎並沒有足夠的補充800

我猜一個數組或以某種方式連接到.csv會這樣做,但我不確定。我會很感激任何幫助。

+0

您是否瞭解該產品[智能優惠券](http://www.woothemes.com/products/smart-coupons/)。使用此產品,您可以創建許多獨特的優惠券代碼,只需點擊幾下即可導入WooCommerce中的所有優惠券,並可將生成的優惠券代碼導出爲CSV文件。此產品爲WooCommerce優惠券提供了許多功能。在產品文檔中,您無法找到自動生成和導入的內容,因爲產品文檔不會很長時間更新。 –

+0

感謝您的建議,它確實看起來可行,但我對添加如此龐大的一系列功能和另一個插件持謹慎態度,因爲一個所需功能的複雜性如此之高並不理想。 –

回答

3

您可以創建的800 diferent數組中的鍵,只是做一個foreach循環重複該過程,你有這樣的OP貼裏面的這個

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'); 
} 

(使用的代碼陣列上的每一個不同的密鑰沒有經過實際測試)

相關問題