色婷婷国产精品免费网站_av在线官网_色综合色综合_欧美精品一区二区三区蜜桃视频_成人免费视频观看视频_国产午夜精品一区二区三区视频

17站長網(wǎng)

17站長網(wǎng) 首頁 編程 PHP編程 查看內(nèi)容

在WooCommerce結(jié)賬中添加帶有收集時(shí)間的自定義選擇字段

2023-1-19 16:57| 查看: 7208 |來源: 互聯(lián)網(wǎng)

我已經(jīng)在我的網(wǎng)站上為收款時(shí)間創(chuàng)建了一個(gè)自定義結(jié)賬字段這是我當(dāng)前的代碼:add_action('woocommerce_before_order_notes','njengah_add_selec ...

我已經(jīng)在我的網(wǎng)站上為收款時(shí)間創(chuàng)建了一個(gè)自定義結(jié)賬字段

這是我當(dāng)前的代碼:

add_action('woocommerce_before_order_notes', 'njengah_add_select_checkout_field');
function njengah_add_select_checkout_field( $checkout ) {
    woocommerce_form_field( 'daypart', array(
        'type'          => 'select',
        'class'         => array( 'njengah-drop' ),
        'label'         => __( 'Collection Time' ),
        'required'      => true,   
        'options'       => array(
            'blank'   => __( 'Select a collection time', 'njengah' ),
            '5:00_PM' => __( '5:00 PM', 'njengah' ),
            '5:30_PM' => __( '5:30 PM', 'njengah' ),
            '6:00_PM' => __( '6:00 PM', 'njengah' ),
            '6:30_PM' => __( '6:30 PM', 'njengah' ),
            '7:00_PM' => __( '7:00 PM', 'njengah' ),
            '7:30_PM' => __( '7:30 PM', 'njengah' ),
            '8:00_PM' => __( '8:00 PM', 'njengah' )
        )
    ), $checkout->get_value( 'daypart' ));
}

但是,這樣做的目的是在時(shí)間過去后隱藏收集時(shí)間

例如-如果下午6點(diǎn)隱藏:下午5:00和下午5:30

任何幫助都是最好的

使用根據(jù)指定類型檢索當(dāng)前時(shí)間的推薦答案current_time()函數(shù)。

從那時(shí)起,您可以進(jìn)一步定制代碼以滿足您的需求,因此您可以:

function action_woocommerce_before_order_notes( $checkout ) {
    // Open and close time
    $start_time = strtotime( '9:00 AM' );
    $stop_time = strtotime( '1:00 PM' );

    /* END SETTINGS */
    
    // Current time
    $current_time = current_time( 'timestamp' );
    
    // Initialize
    $remaining_times = array();
    $required = true;
    
    // Closed
    if( $current_time > $stop_time || $current_time <= $start_time ) {
        // Default value
        $default[''] = __( 'Closed', 'woocommerce');
        
        // False
        $required = false;
    } else {    
        // Default value
        $default[''] = __( 'Select a collection time', 'woocommerce');
        
        // Determine first value
        $first_value = strtotime( date( 'g:i A', ceil( $current_time / 1800 ) * 1800 ) );
        
        // Add a new option every 30 minutes
        while( $first_value <= $stop_time && $first_value >= $start_time ) {
            $value = date( 'g:i A', $first_value );
            $remaining_times[$value] = $value;
            
            // Add 30 minutes
            $first_value = strtotime( '+30 minutes', $first_value );
        }
    }
    
    // Options
    $options = array_merge( $default, $remaining_times );

    // Add field
    woocommerce_form_field( 'daypart', array(
        'type'          => 'select',
        'class'         => array( 'njengah-drop' ),
        'label'         => __( 'Collection Time', 'woocommerce' ),
        'required'      => $required,  
        'options'       => $options,
    ), $checkout->get_value( 'daypart' ));
}
add_action( 'woocommerce_before_order_notes', 'action_woocommerce_before_order_notes', 10, 1 );

例如

  • 當(dāng)前時(shí)間=上午9:14

  • 第一個(gè)值=上午9:30

  • 上一個(gè)值=下午1:00(停止時(shí)間)

附加問題:假設(shè)開始時(shí)間為下午5:00,停止時(shí)間為晚上8:00我如何讓客戶有機(jī)會(huì)從中午12:00開始訂購,而第一個(gè)時(shí)段是下午5:00?

改用以下代碼:

function action_woocommerce_before_order_notes( $checkout ) {
    // Display time, open and close time
    $display_time = strtotime( '12:00 PM' );
    $start_time = strtotime( '5:00 PM' );
    $stop_time = strtotime( '8:00 PM' );

    // END SETTINGS
    
    // Current time
    $current_time = current_time( 'timestamp' );
    
    // Initialize
    $remaining_times = array();
    $required = true;
    
    // Closed
    if( $current_time > $stop_time || $current_time <= $display_time ) {
        // Default value
        $default[''] = __( 'Closed', 'woocommerce');
        
        // False
        $required = false;
    } else {    
        // Default value
        $default[''] = __( 'Select a collection time', 'woocommerce');
        
        // Determine first value
        $first_value = strtotime( date( 'g:i A', ceil( $current_time / 1800 ) * 1800 ) );
        
        // First value is less than start time
        if ( $first_value < $start_time ) {
            $first_value = $start_time;
        }
        
        // Add a new option every 30 minutes
        while( $first_value <= $stop_time && $first_value >= $start_time ) {
            $value = date( 'g:i A', $first_value );
            $remaining_times[$value] = $value;
            
            // Add 30 minutes
            $first_value = strtotime( '+30 minutes', $first_value );
        }
    }
    
    // Options
    $options = array_merge( $default, $remaining_times );

    // Add field
    woocommerce_form_field( 'daypart', array(
        'type'          => 'select',
        'class'         => array( 'njengah-drop' ),
        'label'         => __( 'Collection Time', 'woocommerce' ),
        'required'      => $required,  
        'options'       => $options,
    ), $checkout->get_value( 'daypart' ));
}
add_action( 'woocommerce_before_order_notes', 'action_woocommerce_before_order_notes', 10, 1 );

例如

  • 當(dāng)前時(shí)間=下午12:05

  • 第一個(gè)值=下午5:00

  • 最后一個(gè)值=晚上8:00(停止時(shí)間)

本文最后更新于 2023-1-19 16:57,某些文章具有時(shí)效性,若有錯(cuò)誤或已失效,請?jiān)诰W(wǎng)站留言或聯(lián)系站長:17tui@17tui.com
·END·
站長網(wǎng)微信號(hào):w17tui,關(guān)注站長、創(chuàng)業(yè)、關(guān)注互聯(lián)網(wǎng)人 - 互聯(lián)網(wǎng)創(chuàng)業(yè)者營銷服務(wù)中心

免責(zé)聲明:本站部分文章和圖片均來自用戶投稿和網(wǎng)絡(luò)收集,旨在傳播知識(shí),文章和圖片版權(quán)歸原作者及原出處所有,僅供學(xué)習(xí)與參考,請勿用于商業(yè)用途,如果損害了您的權(quán)利,請聯(lián)系我們及時(shí)修正或刪除。謝謝!

17站長網(wǎng)微信二維碼

始終以前瞻性的眼光聚焦站長、創(chuàng)業(yè)、互聯(lián)網(wǎng)等領(lǐng)域,為您提供最新最全的互聯(lián)網(wǎng)資訊,幫助站長轉(zhuǎn)型升級(jí),為互聯(lián)網(wǎng)創(chuàng)業(yè)者提供更加優(yōu)質(zhì)的創(chuàng)業(yè)信息和品牌營銷服務(wù),與站長一起進(jìn)步!讓互聯(lián)網(wǎng)創(chuàng)業(yè)者不再孤獨(dú)!

掃一掃,關(guān)注站長網(wǎng)微信

大家都在看

    熱門排行

      最近更新

        返回頂部
        主站蜘蛛池模板: 懂色av色吟av夜夜嗨 | 好色婷婷 | 96看片| 欧美日韩中文字幕在线 | 日韩精品国产精品 | 在线观看欧美日韩视频 | 久久精品亚洲 | 国产又粗又大又长 | 日产精品久久久一区二区 | 黑人系列合集h | 成人精品免费视频 | 欧美精品福利 | 91免费国产 | 91免费版看片 | 国产一区精品在线观看 | 午夜视频一区二区三区 | 日本特级黄色片 | 国产黄网| 日本免费在线观看 | 亚洲精品福利 | 久久国产综合 | 日本成人精品 | 日韩a级片 | 久操精品 | 国产操操操 | 亚洲高清视频在线 | 国产精品一区在线观看 | 成人在线小视频 | 久久久xxx | 黄色一级片网站 | 中文字幕超清在线观看 | 亚洲精品免费在线观看 | 成人精品一区二区三区 | 午夜影院免费 | 一区二区网站 | 国产免费黄色 | 在线一级片| 免费看黄色的视频 | av免费网站| 黄色xxxxx| 亚洲一区二区三区在线播放 |