2017-09-01 2 views
0
私はいくつかの時間のためにこれを思ってきたけど、これまでのブランクを描いた

...Woocommerce:n番目の注文の無料ギフトを追加できますか?

誰もが完了すると、自動的に任意のWoocommerce製品のために自由なギフトを追加することが可能であるかどうかを知っていますか?サイトごと、または製品ごとに値が異なる

I.E.
製品がカートに追加され、ユーザーは無料ギフトページにリダイレクトまたはポップアップしたり、電子メールを受信されるか
項目
注文が支払われる/完了との100回目のオーダーである(最も実用的である方)

希望:-)これは関連しているようです - どんなポインタも大いに感謝しています!

エド

EDIT: だから、アキ(下記)およびオンライン検索からいくつかの助けた後、私はこれを作ってみたが、それでも私は何をしないのです...それは仕事を得ることができません?このため

add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1); 

function custom_process_order($order_id) { 

//First We are chceking order is paid or not with the order metafields 
$transactionId = get_post_meta($order_id,'_transaction_id', true); 
if(isset($transactionId)) 
{ 
    //getting the count of order 
    $orderCount = get_option('orderCount'); 
    if($orderCount == 99) 
    { 
     //let's reset order count option zero 
     $orderCount = 0; 

     //send email or redirect code or popup code 
$message = "You're the 100th order of this item, so please, have one on us..Free gift!"; 
echo "<script type='text/javascript'>alert('$message');</script>"; 
    }else 
    { 
     $orderCount = (int) $orderCount+1; 
    } 
    update_option('orderCount', $orderCount); 
} 
} 

答えて

0

あなたはあなたがあなたの目標に達することができるよりも、回数を設定する必要がfleasible直接それはいくつかのコードを実行する必要があります。

update_option関数の助けを借りて注文数を設定する必要があります。

add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1); 

function custom_process_order($order_id) { 

//First We are chceking order is paid or not with the order metafields 
$transactionId = get_post_meta($order_id,'_transaction_id', true); 
if(isset($transactionId)) 
{ 
    //getting the count of order 
    $orderCount = get_option('orderCount'); 
    if($orderCount == 99) 
    { 
     //let's reset order count option zero 
     $orderCount = 0; 

     //send email or redirect code or popup code 

    }else 
    { 
     $orderCount = (int) $orderCount+1; 
    } 
    update_option('orderCount', $orderCount); 
} 
} 
+0

ありがとう、本当に助かりました!だから私は自分のサイトに合うようにこれを微調整し、実際に贈り物の通知を表示するには "...ポップアップコード"& "} else ..."の間に何かを追加する必要がありますか? :-)ちょうど確かに - 私は明らかにちょっとしたノブです!ありがとう、ちょっと後でこれを試して、私の進歩状況を報告します! –

+0

あなたのコードをif条件に入れてください...あなたが私の答えに投票してくれたよりもうまくいくならば、他の人がこのコードを使うことができます。 –

+0

ありがとうございましたAki - いくつかのホームの改善を開始しようとしていますので、今夜のコードですぐにひどいことになります。 –

関連する問題