Skip to main content

How to create custom guest popup for checkout with wordpress menu in wordpress.

Create custom guest popup for checkout with wordpress menu in wordpress.

Paste in function.php

function override_checkout_email_field( $fields ) {
global $wpdb;
  $popup_id = $_COOKIE['popup_id'];
global $wpdb;
$tablename = $wpdb->prefix . "guest_users";
$result = $wpdb->get_results ("SELECT * FROM $tablename WHERE id=$popup_id");
foreach ( $result as $print )   {

}
$survey_email = $print->email;
$survey_phone = $print->phone;
    global $woocommerce;
    //$survey_email = $woocommerce->session->get('survey_email');
    if(!is_null($survey_email)) {
      $fields['billing']['billing_email']['default'] = $survey_email;
    }
     if(!is_null($survey_phone)) {
      $fields['billing']['billing_phone']['default'] = $survey_phone;
    } 
    return $fields;
}

add_filter( 'woocommerce_checkout_fields' , 'override_checkout_email_field' );


// Show the popup to fetch email and phone number and store in the database




function guest_popup(){
$popup_id = $_COOKIE['popup_id'];
if(isset($_POST['guest_popup_bt'])){
$email = $_POST['email'];
$phone = $_POST['phone'];
date_default_timezone_set('Asia/Kolkata');
$date = date('d-m-Y h:i:s a');
global $wpdb;
$table_name = $wpdb->prefix . "guest_users";
$wpdb->insert($table_name, array('email' => $email, 'phone' => $phone, 'created_at' => $date) ); 
$lastid = $wpdb->insert_id;
if(!empty($lastid)){
//setcookie('popup_id', $lastid, strtotime('+1 day'), COOKIEPATH, COOKIE_DOMAIN);
setcookie('popup_id', $lastid, strtotime("+1 year"), COOKIEPATH, COOKIE_DOMAIN);
if ( ! WC()->cart->get_cart_contents_count() == 0 ) { 
wp_redirect(site_url().'/checkout');
}else{
wp_redirect(site_url().'/shop');
}
}
}
?>
<?php
if(!is_user_logged_in() && is_cart() && empty($popup_id)){
?>
<style>
.popup-container {
    width: 100%;
    height: 100vh;
    background-color: #000000bf;
    position: fixed;
    display: flex;
    justify-content: Center;
    align-items: center;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 9999999;
    left: 0;
}

.popup-box input[type="email"],input[type="number"] {
    width: 100%;
    font-size: 15px;
    padding: 7px 7px;
}
input.guest_popup_bt {
    padding: 5px 16px;
    background: #000;
    border: #000;
    color: white;
    font-weight: 400;
    font-size: 16px;
}
.form-filed-box {
    margin-top: 10px;
}
.popup-box h4 {
    margin: 0;
    font-size: 17px;
    text-align: center;
    font-weight: 400;
    letter-spacing: 1px;
    margin-bottom: 12px;
}
.popup-box {
    padding: 59px 37px;
    background: white;
    border-radius: 9px;
    width: 386px;
position:relative;
}

.popup_close_bt {
    background: #000;
    color: White;
    position: absolute;
    right: -15px;
    top: -15px;
    border-radius: 200%;
    width: 30px;
    height: 30px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
cursor:pointer;
}
</style>
<script>
jQuery(document).ready(function($){
$('.popup_close_bt').click(function(){
$('.popup-container').css('display','none');
});

if (typeof $.cookie('popup_id') === 'undefined'){

$('.checkout-button').click(function(e){
e.preventDefault;
jQuery('.popup-container').css('display','flex');
return false;
});
}
});
</script>
<div class="popup-container">
<div class="popup-box">
<div class="popup_close_bt">X</div>
<form action="" method="post">
<h4>Please enter the following detail to move forward</h4>
<div class="form-filed-box">
<label>Email</label>
<input type="email" name="email" >
</div>
<div class="form-filed-box">
<label>Phone no.</label>
<input type="text" name="phone" >
</div>
<div class="form-filed-box">
<input type="submit" name="guest_popup_bt" class="guest_popup_bt" value="Submit">
</div>
</form>
</div>
</div>
<?php
}
}
add_action('wp_head','guest_popup');


add_action("admin_menu", "addMenu");

function addMenu() {
    add_menu_page("Guest Info", "Guest Info", "edit_posts",
        "guest-popup", "displayPage", null,10);
}

add_filter("custom_menu_order", "allowMenuStructure");
add_filter("menu_order", "loadMenuStructure");

function displayPage() {
?>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.min.css">



<script src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>  



<script>

$(document).ready(function() {
    $('#example').DataTable( {
      /*   dom: 'Bfrtip',
        buttons: [
            'copy', 'excelFlash', 'excel', 'pdf', 'print',{
            text: 'Reload',
            action: function ( e, dt, node, config ) {
                dt.ajax.reload();
            }
        }
        ] */
    } );
} );

</script>


<table id="example" class="display nowrap" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>S.r</th>
                <th>Date</th>
                <th>Email</th>
                <th>Phone</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>S.r</th>
                <th>Date</th>
                <th>Email</th>
                <th>Phone</th>
            </tr>
        </tfoot>
        <tbody>
<?php
global $wpdb;
$tablename = $wpdb->prefix . "guest_users";
$result = $wpdb->get_results ("SELECT * FROM $tablename order by Id DESC");
//print_r($result);
$i = 1 ;
foreach ( $result as $print )   {
?>
            <tr>
                <td><?php echo $i; ?></td>
                <td><?php echo $print->created_at; ?></td>
                <td><a href="mailto:<?php echo $print->email; ?>"><?php echo $print->email; ?></a></td>
                <td><a href="tel:<?php echo $print->phone; ?>"><?php echo $print->phone; ?></a></td>

            </tr>
<?php
$i++;
}
?>
        </tbody>
    </table>
<?php
}

Comments

Popular posts from this blog

How to use inner html value or data in php from javascript(innerHTML)?

 use inner html value or data in php from javascript(innerHTML)? <html> <body> <p id="demo">use inner html value in php(innerhtml)</p> <script>   var jassi = document.getElementById("demo").innerHTML;   //document.write(jassi); </script> <?php $jassi = '<script>document.write(jassi);</script>'; echo $jassi; ?> </body> </html>

How to get store data from WCFM(Best Multi Vendor Marketplace) Plugin?

 Get store data from WCFM(Best Multi Vendor Marketplace) Plugin. global $WCFM, $WCFMmp, $wp, $WCFM_Query, $post; $store_id = ''; if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); } if (  wcfm_is_store_page() ) { $wcfm_store_url = get_option( 'wcfm_store_url', 'store' ); $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) ); $store_id  = 0; if ( !empty( $store_name ) ) { $store_user = get_user_by( 'slug', $store_name ); } $store_id    = $store_user->ID; } $user_id = $store_id;  $vendor_data = get_user_meta( $user_id, 'wcfmmp_profile_settings', true ); $street_1 = $vendor_data['address']['street_1']; $street_2 = $vendor_data['address']['street_2']; $city     = $vendor_data['address']['city']; $zip      = $vendor_data['address']['zip&#

How to create login with phone number in woocommerce wordpress?

Create login with phone number in woocommerce wordpress. function wooc_extra_register_fields() {?>        <p class="form-row form-row-wide">        <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>        <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />        </p>            <?php  }  add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );  function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) { if ( isset( $_POST['billing_phone'] ) ) {    $hasPhoneNumber= get_users('meta_value='.$_POST['billing_phone']);    if ( !empty($hasPhoneNumber)) {      $validation_er