1
私のサイトは、ユーザーが長時間にわたってメンバーになっている場合、ユーザーのクーポンを動的に提供します。私がクーポンを生成しているときに、そのクーポンに説明を割り当てたいと思います。しかし、投稿のメタデータをdescription
というキーで更新して説明を割り当てることができないようで、docsができるはずです。WooCommerceでクーポンの説明を設定する
$percent = 25;//DISCOUNT PERCENTAGE
$coupon_code = 'testcoupon'; //Coupon Code
$discount_type = 'percent'; // Type: fixed_cart, percent, fixed_product, percent_product
//ASSIGN COUPON AND DISCOUNT PERCENTAGE
$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);//SET DICOUNT TO BE PERCENTAGE BASED
update_post_meta($new_coupon_id, 'coupon_amount', $percent);//SET DISCOUNT PERCENTAGE
update_post_meta($new_coupon_id, 'individual_use', 'yes');//ONLY ONE CUPON BE USED AT A TIME
update_post_meta($new_coupon_id, 'product_ids', ''); //INCLUDE ALL PRODUCTS
update_post_meta($new_coupon_id, 'exclude_product_ids', '');//DO NOT EXCLUDE ANY PRODUCTS
update_post_meta($new_coupon_id, 'usage_limit', '1');//ONE TIME USE
update_post_meta($new_coupon_id, 'expiry_date', strtotime("+6 months"));
update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
update_post_meta($new_coupon_id, 'free_shipping', 'no');//DO NOT GIVE FREE SHIPPING
//ASSIGN DESCRIPTION TO COUPON
update_post_meta($new_coupon_id, 'description', 'This is an example description used for the example coupon');
は、他にどのように私は説明を追加することに取り掛かる必要があります。
は現在、私はそうのような記述を割り当てるしようとしていますか?$percent = 25;//DISCOUNT PERCENTAGE
$coupon_code = 'testcoupon'; //Coupon Code
$discount_type = 'percent'; // Type: fixed_cart, percent, fixed_product, percent_product
$description = __('This is an example description used for the example coupon');
//ASSIGN COUPON AND DISCOUNT PERCENTAGE
$coupon = array(
'post_title' => $coupon_code,
'post_content' => '',
'post_excerpt' => $description, // <== HERE goes the description
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'shop_coupon'
);
$new_coupon_id = wp_insert_post($coupon);
## …/… and so on
または:
私はメイドインをintあなたのクーポンを作成するWC_Couponオブジェクトとメソッドを代わりに使用して、更新を盗んで... – LoicTheAztec
恐ろしい!どうもありがとうございました!あまりにも悪い私はあなたの答えに2つの+1を与えることはできません –