2017-06-12 27 views
0

基本的には、私が望むやり方で、/ my-account /ページで実行される関数を追加したいという理由で、リダイレクトを行うことができません。現在のユーザー直前の10秒間に製品AまたはBを注文しました(ステータスはオートコンプリートオーダープラグインを使用して完了しました)。そうであれば、その機能に指定されたカスタムのありがとうページにリダイレクトされます。ユーザーが最近10秒間に注文を完了したかどうかを確認します(woocommerce)。

最近の注文を引き出す機能がたくさんありますが、正しい方向に向いているかどうかはわかりません。最新のユーザーのタイムスタンプと製品IDを取得するにはどうしたらいいですか?これを/ my-account/pageに結びつけるフックがあるのですか?それともjavascript/phpをハックする必要がありますか?

答えて

0

購入後すぐにコードを実行するのはどうですか? どの製品であったかをチェックして、必要に応じてチェックします。その後、カスタムのおまけページにリダイレクトします。ここで

add_action('woocommerce_thankyou', 'my_custom_code'); 
function my_custom_code($order_id) { 

    // Lets grab the order 
    $order = wc_get_order($order_id); 

    // do stuff 

} 
0

は私がやってしまったものです:

  • は、列を追加するためのID(使用するフィルタを含む「マイアカウント」ページ の「受注」テーブルにカスタム列を追加しました - SKU - と は、SKU欄に製品ID を追加するorders.phpページのロジックを更新

    function new_orders_columns($columns = array()) { $columns['product-name'] = __('SKU', 'Text Domain'); return $columns; } add_filter('woocommerce_account_orders_columns', 'new_orders_columns');

  • 現在の日付を引き出​​すjQueryスクリプト(「My アカウント」ページに追加されたショートコード経由でPHPにエコーされます)、日付カラムの日付時刻 属性、およびSKU カラムの商品IDテキスト最初の行 - つまり直近ため、現在の時刻との差と 注文時間を見つけて、秒

  • にその数を変換するためにJavascriptを使用

  • はその時 の値に基づいて、条件付きのリダイレクトを追加しました差が10(秒)未満であり、その製品ID 特定のIDた

    function mycustomorder_redirect() { if (is_user_logged_in()) { date_default_timezone_set('America/New_York'); $time_now = date('c'); echo '<script>jQuery("document").ready(function() { // //Get most recent order datetime var lastorder_td = jQuery("td.woocommerce-orders-table__cell-order-date:eq(0) time").attr("datetime"); // //Get most recent order product id var product_check = jQuery("td.woocommerce-orders-table__cell-product-name:eq(0)").text(); // //Remove whitespace product_check = product_check.replace(/(^\s+|\s+$)/g,""); // //Get current datetime var current_wrap = "' . $time_now . '"; // //Remove +00:00 or -00:00 lastorder_td = lastorder_td.substring(0, lastorder_td.length - 6); current_wrap = current_wrap.substring(0, current_wrap.length - 6); // //Convert to javascript date var column_a = new Date(current_wrap); var column_b = new Date(lastorder_td); // //Find time difference var dif = column_a - column_b; // //Convert to seconds var seconds_toredirect = dif/1000; // //Add redirect if (seconds_toredirect < 10 && (product_check == 1 || product_check == 2)) { window.location.replace("https://exampleurl.com/page/"); } }); </script>'; } } add_shortcode('order-custom', 'mycustomorder_redirect');

関連する問題