<?php
$proID = get_the_id();
// $current_user = wp_get_current_user();
session_start();
$author_id = get_post_field( 'post_author', $proID ); 
//$author_name = get_the_author_meta( 'user_login', $author_id );


       $_SESSION['wl_redirect_status'] =  1;
        $_SESSION['wl_redirect_url'] =  get_permalink($proID);

    if(isset($_GET['wl_reg_msg'])){
        if($_GET['wl_reg_msg'] == 'created'){
            echo '<div class="alert alert-success" role="alert">Success! User successfully created.</div>';
        }
    }
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $proID ), 'full' );
    $price = get_post_meta($proID,'lm_pro_price',true);
    $lead = get_post_meta($proID,'lm_req_leads',true);
    global $wpdb;
    $table_name = $wpdb->prefix . 'refer_info';
    $current_user_id = get_current_user_id();
    if(!empty($_SESSION['wl_user']) && !empty($_SESSION['wl_pro']) && $current_user_id != $_SESSION['wl_user'] && $current_user_id > 0){
        $ref_data = $wpdb->get_results("SELECT * FROM $table_name WHERE user_id = $current_user_id AND product = ".$_SESSION['wl_pro']." AND refer_by = ".$_SESSION['wl_user'] );
        //$current_user_id = get_current_user_id();
        // $urlAttr = rawurlencode( base64_encode($current_user_id.'_pro_'.$proID) );
        if($ref_data == NULL){	
            $data = [
                    'user_id' => intval($current_user_id),
                    'refer_by' => intval($_SESSION['wl_user']),
                    'product' => intval($_SESSION['wl_pro']),
                    'status' => 'active',
                    'refer_at' => current_time('mysql')
                ];

            $insDATA = $wpdb->insert($table_name, $data);
            if($insDATA){
                $_SESSION['wl_user'] = '';
                $_SESSION['wl_pro'] = '';
            }
        }
    }
?>

<?php 
    $urlAttr = rawurlencode( base64_encode($current_user_id.'_pro_'.$proID) );
?>


<style>
.product-img img{
    min-height: 500px;
    min-width: auto;
}

.product_step{
    border: 1px solid #584040;
    padding: 20px;
}
ul {
    list-style-type: none;
}
.refer_link input{
    width: 75%;
}
.copy_link_btn{
    margin-left: 20px;
    padding: 10px;
    background: #7a7070;
    color: #f7f4f4;
    font-weight: 600;
}
.steps_head{
font-size: 24px;
    font-weight: bold;
    background: linear-gradient(135deg, #f5a623, #f76c6c);
    backdrop-filter: blur(12px);
    border-radius: 15px;
    color: #ffffff;
    padding: 15px 25px;
    margin-bottom: 20px;
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15);
    text-transform: uppercase;
    letter-spacing: 1px;
    width: fit-content;
    display: inline-block
}
#span_copy_link{
    margin: 10px;
    color: #22bf22;
    font-size: 14px;
    font-weight: 700;
}
.stripes {
  background-image: linear-gradient(45deg, #000 25%, transparent 25%, transparent 50%, #000 50%, #000 75%, transparent 75%, #fff);
  background-size: 10px 5px;
}<?php if ( is_user_logged_in() ){?>
.product_step ul li.log_tick:after{
    content: '\2713';
    display: inline-block;
    color: #24c724;
    padding: 0 6px 0 0;
    font-size: 20px;
    font-weight: 600;
}
<?php } ?>
    </style>

<div class="col-4 col-sm-6 col-lg-4 col-xl-4">
    <div class="product-img">
        <img src="<?php echo $image[0];?>" style="border: 1px solid #910606;">
    </div>
</div>

<div class="col-8 col-sm-6 col-lg-8 col-xl-8">       
    <div class="product-info">
        <h3><?php echo the_title();?></h3>

        <h3 style="font-size: 30px;color: #b32800;">Price : $<?=$price?></h3>
        <h3 style="font-size: 30px;color:#d60606;margin-top: 50px;">Get the product for free.</h3>
        <div class="product_step">
            
            <h4 class="steps_head">Steps to get free: </h4>
            <ul>
            <li class="log_tick">1. Please sign up here </li>
            <li>2. Copy the below link and share</li>
            <li>3. Ask <?=$lead?> people to signup through this URL</li>
            <li>4. Congratulation you will have this product for free</li>
            </ul>
        
            <h4 style="color:#274c85;">Referral LINK : </h4>
            <div class="refer_link">
                <?php if ( is_user_logged_in() ) { ?>
                <input type="text" class="refer_link" id="refer_link" name="linkurl" size="48" value="<?php echo  get_the_permalink(165) . '?key=' . $urlAttr ;?>" disabled>
                <!-- <a href="<?php echo  get_the_permalink(165) . '?key=' . $urlAttr ;?>" target="blank"></a> -->
                <button class="copy_link_btn" onclick="copy_link()">Copy</button><label><span id="span_copy_link"></span></label>
                <?php }else{ ?>
                    <input type="text" class="refer_link stripes" id="refer_link" name="linkurl" size="48"  disabled>
                    <a href="<?php echo  get_the_permalink(156);?>" class="copy_link_btn">Sign UP</a>

              <?php } ?>
            </div>
        </div>
    </div>
</div>

</div>