クーポンがまだ有効である(使用限度に達していない)かどうかを確認し、この状態でコンテンツを表示しようとしています。WooCommerce:クーポンが有効であることを確認してください
これは、特定の訪問者にクーポンコードを渡すことができるようにするためですが、すでに使用限度に達しているクーポンを渡したくないからです。コードが完全にテストされ:)
クーポンがまだ有効である(使用限度に達していない)かどうかを確認し、この状態でコンテンツを表示しようとしています。WooCommerce:クーポンが有効であることを確認してください
これは、特定の訪問者にクーポンコードを渡すことができるようにするためですが、すでに使用限度に達しているクーポンを渡したくないからです。コードが完全にテストされ:)
$code = 'test123';
$coupon = new WC_Coupon($code);
$coupon_post = get_post($coupon->id);
$coupon_data = array(
'id' => $coupon->id,
'code' => $coupon->code,
'type' => $coupon->type,
'created_at' => $coupon_post->post_date_gmt,
'updated_at' => $coupon_post->post_modified_gmt,
'amount' => wc_format_decimal($coupon->coupon_amount, 2),
'individual_use' => ('yes' === $coupon->individual_use),
'product_ids' => array_map('absint', (array) $coupon->product_ids),
'exclude_product_ids' => array_map('absint', (array) $coupon->exclude_product_ids),
'usage_limit' => (!empty($coupon->usage_limit)) ? $coupon->usage_limit : null,
'usage_count' => (int) $coupon->usage_count,
'expiry_date' => (!empty($coupon->expiry_date)) ? date('Y-m-d', $coupon->expiry_date) : null,
'enable_free_shipping' => $coupon->enable_free_shipping(),
'product_category_ids' => array_map('absint', (array) $coupon->product_categories),
'exclude_product_category_ids' => array_map('absint', (array) $coupon->exclude_product_categories),
'exclude_sale_items' => $coupon->exclude_sale_items(),
'minimum_amount' => wc_format_decimal($coupon->minimum_amount, 2),
'maximum_amount' => wc_format_decimal($coupon->maximum_amount, 2),
'customer_emails' => $coupon->customer_email,
'description' => $coupon_post->post_excerpt,
);
$usage_left = $coupon_data['usage_limit'] - $coupon_data['usage_count'];
if ($usage_left > 0) {
echo 'Coupon Valid';
}
else {
echo 'Coupon Usage Limit Reached';
}
ここにすべてのヘルプは素晴らしいことだ
<?php if (coupon('mycouponcode') isvalid) {
echo "Coupon Valid"
} else {
echo "Coupon Usage Limit Reached"
} ?>
:私はPHPでこれを達成し、このようなものにするためにコードを想像しようとしています
機能的。
リファレンス
これは常に「クーポン使用限度額に達しました」を返しています。私はtest123を多くのクーポン(有効期限切れ、使い切って、残しておいたものなど)で置き換えましたが、喜びはありません:( – NuclearApe
@ NuclearApe:任意の有効なクーポン印刷 '$ coupon_data ['usage_limit']'、 '$ coupon_data ['usage_count –
WC_Couponクラス( 'is_valid()'と 'is_valid_for_cart()')に関連するメソッドが2つあります** **しかし、残念ながら、彼らはうまくいきません... ** **バグ**常に**偽を返します**。私はワードプレスでスレッドを投稿しました。> Woocommerceサポートスレッド:https://wordpress.org// – LoicTheAztec
クーポンは多くの基準に依存していますので、使用限度のみを使用したいのですか? –
@RaunakGuptaええ、私が興味を持っている唯一の基準は、使用制限です:) – NuclearApe