WooCommerce Security Update 402 -> 404 break site

Just wondering if anyone else has had this issue, our site is currently running 4.0.2 albeit an old version of WooCommerce, however, there was a security update over the weekend to remove Paypal standard from WooCommerce which forces an update to 4.0.4.

The site has tried to do this but it didn’t successfully complete the update and in turn break the site with the following error:

PHP Fatal error: Uncaught Error: Call to undefined function is_woocommerce()

To fix the issue we manually download 4.0.4 and over write the files, however, within a couple of hours we have the same issue again.

WordPress version: 5.7.5
WooCommerce Version: 4.0.4

Sql query with where conditions

I have table ‘zipcode’ and that have column ‘code’. Code column have staring of zipcode like

395
453
302
1203
12

I want to write sql query from that i can identify is this zip code match with records?

Valid Input zipcode

395004
395152
3952
1256

Safe to call WooCommerce, WordPress and CoCart endpoints in frontend? I need your opinion

Question

I got a question about security. I am building a mobile webshop in Flutter. Is it bad to make those API calls in the frontend? Should I make a separate backend for it in Node for example?

I have also read that you can ‘create’ your own endpoints in WordPress with PHP. What about that? Does that make it any safer or not?

What endpoints do I use?

There is an existing WooCommerce API to retrieve products, get categories, create orders on the WooCommerce API. On the CoCart API, you can retrieve the cart, add to cart, delete cart, etc…

For the Mollie payment APIs, I think it is better to make a backend.

My take on it

I think it is fine to call those endpoints in the frontend. I have seen Flutter packages for WooCommerce to call those endpoints. Yes, I do send the basic auth in the headers… so I am not sure how ‘dangerous’ that is.

But on the other side. What can the ‘hacker’ do? They can see all the products, that is fine I guess. I am not sure if they can create orders… They cannot steal money at least 🙂

Reference code

For reference, here is a piece of code when calling an endpoint:

Future<Product> getProductById(int productId) async {
    String basicAuth =
        'Basic ' + base64Encode(utf8.encode('$username:$password'));
    print(basicAuth);

    var response = await http.get(
        Uri.parse(
            'https://websitename/wp-json/wc/v3/products/${productId}'),
        headers: <String, String>{'Authorization': basicAuth});
    if (response.statusCode == 200) {
      return Product.fromJson(jsonDecode(response.body));
    } else {
      throw Exception('Failed');
    }
  }

Let me know your opinion!

Hide woocommerce notice with checkbox based shipping on class

Want to hide woocommerce notice with jQuery on checkout page if specific shipping class checkbox is checked. Trying to make with this code but not working for me 🙁

//Hide Delivery Message in case Express Shipping Checked

add_action( 'woocommerce_checkout_process', 'hide_notice_billing' );
function hide_notice_billing(){
    ?>
        <script>
        jQuery(function($){
           $(document).ready(function() {
    $(document).on("click", "#shipping_method_0_flat_rate-12", function(e) {
       var checked = $(this).find("input:checkbox").is(":checked");
       if (checked) {
           $('.woocommerce-message').hide(300);
       } else {
           $('.woocommerce-message').show(300);
       }
    });
});
        });
    </script>
    <?php
}

Get data from WooCommerce object [duplicate]

I’m struggling to get specific data from wc_get_orders().

Here is the code:

$args   = array(
    'numberposts' => - 1,
    'orderby'     => 'date',
    'order'       => 'DESC',
    'customer_id' => get_current_user_id(),
);
$orders = wc_get_orders( $args );
echo '<pre>', var_dump( $orders ), '</pre>';

Here is the part of the object:

["meta_data":protected]=>
    array(4) {
      [0]=>
      object(WC_Meta_Data)#3544 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1135)
          ["key"]=>
          string(13) "is_vat_exempt"
          ["value"]=>
          string(2) "no"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1135)
          ["key"]=>
          string(13) "is_vat_exempt"
          ["value"]=>
          string(2) "no"
        }
      }
      [1]=>
      object(WC_Meta_Data)#3545 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1136)
          ["key"]=>
          string(13) "tip_korisnika"
          ["value"]=>
          string(13) "Fizičko lice"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1136)
          ["key"]=>
          string(13) "tip_korisnika"
          ["value"]=>
          string(13) "Fizičko lice"
        }
      }
      [2]=>
      object(WC_Meta_Data)#3546 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1137)
          ["key"]=>
          string(12) "fs4e_methods"
          ["value"]=>
          string(5) "obuka"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1137)
          ["key"]=>
          string(12) "fs4e_methods"
          ["value"]=>
          string(5) "obuka"
        }
      }
      [3]=>

I’m trying to get the value of tip_korisinka, which is inside WC_Meta_Data that seems to be protected. Check this screenshot: https://prnt.sc/CI-UfqEkuuag

This is one of the solutions without success that I have tried so far:

foreach ( $orders as $key => $value ) {
    echo $key->$value['tip_korisnika'];
}

Any help would be appreciated.

How to get php database values before the page has loaded using javascript?

So i have 3 pages. upload.php, main.php and script.js. Upload.php lists some database entries, and has a button behind each entry for more info on the entry. When you press the button it gives the ID value from the database with POST in the url and so it loads the info in main.php with the given id.

So here is the problem, i have a javascript file: script.js which needs those db values. I watched a tutorial on passing a variable from php to js using ajax. But the problem is that the values on main are only posted when you press the button in upload.php. Which means when i run the script it immeadiatly goes to main.php and states that the values are empty. Which is true ofcourse.

How do i make the javascript get the values from main/ or database directly?

Im very new to js.

Optimize laravel eloquent query

hello there i am working on a project with 30000 records, i want to print all the records on the paper, but when excute the following command,it keeps on loading the data until it runs out of memory, keep in mind i am fetching data with three different tables using relations with user_id in common in all the tables, i want to optimize the query, so that i can print all the user records seamlessly

$users= AppUser::with(['withdarawals','deposits'])->get()->groupBy('id');
        dd($users);

Relation latest of many without ID

Sensors table

id  name        
1   Sensor no1
2   Sensor no2
3   Sensor no3

Temperatures table (log table)

temperature  sensor_id   timestamp
2.85         1           2021-10-19 18:37:34
5.05         2           2021-10-19 18:37:34
2.90         3           2021-10-20 18:37:34
5.65         1           2021-10-21 18:37:34
21.5         3           2021-10-22 18:37:34

In eloquent I have sensor model with relation

public function latestTemperature()
{
    return $this->hasOne(Temperature::class)->latestOfMany();
}

I get SQL error that temperatures.id does not exist. – I do not have ID in that table.
How can I tell it to where sensor id = x order by timestamp desc limit 1 or something?

Unknown column 'temperatures.id' 'field list'-s (SQL: select `temperatures`.* from `temperatures` inner join (select MAX(`temperatures`.`id`) as `id_aggregate`, `temperatures`.`sensor_id` from `temperatures` where `temperatures`.`sensor_id` in (1) group by `temperatures`.`sensor_id`) as `latestOfMany` on `latestOfMany`.`id_aggregate` = `temperatures`.`id` and `latestOfMany`.`sensor_id` = `temperatures`.`sensor_id`)

Use return data from one function in another and pass it to Smarty template

What I’m trying to do is to have one datatable probably as a template and passing different datas on different pages.

Example functions.php

function force() {
    global $DBconn;
    $q =  "SELECT * FROM table";
    $res = $DBconn->query($q);                              
    
    return $this->result;
}

function force_1() {
    global $DBconn;
    $q =  "SELECT * FROM table_1";
    $res = $DBconn->query($q);                              
    return $this->result;
}

function table() {

      echo '
         <table class="sortable">
            <thead>
            <tr>
                <th>
                    Title
                </th>
            </tr>
            </thead>
            <tbody>';
                foreach ($this->result as $key) {
               echo ' <tr>
                    <td>
                        $key->name
                    </td>
                </tr>';
                }
            echo '</tbody>
        </table>';
    }
  return true;
}

Then in the page.php

$table = table();
$smarty->assign("table", $table);

and page.tpl

<div> {$table} </div>

Currently nothing showed on page, not even an error or something. So:

  1. Is this the way that should be done? With using the returned result in either function and then pass it to the smarty template?

How to count number of rows that gets updated

I have made this code for the Controller:

public function updateUncompletedCarts(Request $request)
    {
        $uncompleted = Cart::where('crt_completed',0)->update([
            'crt_completed' => 1,
            'crt_changed' => 1,
        ]);
        $nums = count($uncompleted);
        
        Session::flash('carts-updated',$nums);
        
        return redirect()->back();
    }

Now I simply run an update query and then I wanted to show the number rows that gets affected and add it to a session so I can retrieve that in the Blade, like this:

@if(Session::has('carts-updated'))
    <div class="alert alert-success" role="alert">
        {{ Session::get('carts-updated') }}
        rows gets updated!
    </div>
@endif

But I get this error:

count(): Parameter must be an array or an object that implements Countable

Which is pointing to this line:

$nums = count($uncompleted);

So what’s going wrong here? How can I fix this issue?

Why the data is still updating even the textbox is empty? (Vue 2/Axios/PHP)

Good day everyone! When I enter the customer_address it updates the database even if I have not yet input the customer_first_name, customer_last_name and customer_contact_no. But if I don’t input the address he won’t update the row in the database. What do you think is the problem? How can I prevent the input from being empty.

//customer.js
identifyCustomerId : function(customer_id) {
            for(var index = 0; index < this.customers.length; index++) {
                if(customer_id == this.customers[index].customer_id) {
                    this.customer_first_name = this.customers[index].first_name;
                    this.customer_last_name = this.customers[index].last_name;
                    this.customer_contact_no = this.customers[index].contact_no;
                    this.customer_address = this.customers[index].address;
                }
            }
        },
openToggleUpdateForm : function(customer_id) {
            this.updateForm = true;
            this.toggleButton = false;
            this.customer_id = customer_id;
            this.identifyCustomerId(customer_id);

        },
 userValidation : function() {
            if(this.customer_first_name.trim() === "") {
                this.first_name_error = true;
                this.first_name_error_message = "This field is required!";
                console.log(this.first_name_error);
            }
            else {
                this.first_name_error = false;
                this.first_name_error_message = "";
            }
            if(this.customer_last_name.trim() == "") {
                this.last_name_error = true;
                this.last_name_error_message = "This field is required!";
            }
            else {
                this.last_name_error = false;
                this.last_name_error_message = "";
            }
            if(this.customer_contact_no.trim() == "") {
                this.contact_no_error = true;
                this.contact_no_error_message = "This field is required!";
            }
            else {
                this.contact_no_error = false;
                this.contact_no_error_message = "";
            }
            if(this.customer_address.trim() == "") {
                this.address_error = true;
                this.address_error_message = "This field is required!";
            }
            else {
                this.address_error = false;
                this.address_error_message = "";
            }
        },
updateCustomer : function() {
            this.userValidation();
            console.log(this.customer_first_name);
            axios.post(this.urlRoot + this.api + "update_customer.php", {
                customer_id : this.customer_id,
                first_name : this.customer_first_name,
                last_name : this.customer_last_name,
                contact_no : this.customer_contact_no,
                address : this.customer_address
            }).then(function (response) {
                if(response.data.status == "NOT OK") {
                    vm.first_name_error = response.data.first_name_error;
                    vm.last_name_error = response.data.last_name_error;
                    vm.contact_no_error = response.data.contact_no_error;
                    vm.address_error = response.data.address_error;
                } else{
                    console.log(response);
                    vm.retrieveCustomer();
                }
            }); 
        }
//update_customer.php (api)
$customer = new Customer();

    $data = json_decode(file_get_contents("php://input"),true);

    $response = [];

    $response['status'] = "OK";

    if(empty($data['customer_id'])) {
        $response['customer_id_error'] = true;
        $response['status'] = "NOT OK";
    }
    if(empty($data['first_name'])) {
        $response['first_name_error'] = true;
        $response['status'] = "NOT OK";
        echo $data['first_name'];

    }
    if(empty($data['last_name'])) {
        $response['last_name_error'] = true;
        $response['status'] = "NOT OK";
    }
    if(empty($data["contact_no"])) {
        $response["contact_no_error"] = true;
        $response["status"] = "NOT OK";
    }
    if(empty($data['address'])) {
        $response['address_error'] = true;
        $response['status'] = "NOT OK";
    }
    else{
        $customer = new Customer();

        $response['status'] = "OK";

        echo json_encode($response);
        $customer->customer_id = ucwords($data['customer_id']);
        $customer->first_name = ucwords($data['first_name']);
        $customer->last_name = ucwords($data['last_name']);
        $customer->contact_no = $data['contact_no'];
        $customer->address = ucwords($data['address']);
        $customer->updateCustomer();
    }
//customer_page.php ("update button on my table")
<button class="btn btn-secondary" @click="openToggleUpdateForm(customer.customer_id)">Update</button>

//customer_page.php ("update form")
<div class="add-content" v-if="updateForm">
                <h1>Add Customer</h1>
                <label>Firstname: </label>
                <input type="text" name="first_name" :class="{ invalid : first_name_error }" v-model="customer_first_name" required><br>
                <div class="text-danger">{{ first_name_error_message }}</div>
                <label>Lastname: </label>
                <input type="text" name="last_name" :class="{ invalid : last_name_error }" v-model="customer_last_name" required><br>
                <div class="text-danger">{{ last_name_error_message }}</div>
                <label>Contact no.: </label>
                <input type="text" name="contact_no" :class="{ invalid : contact_no_error }" v-model="customer_contact_no" required><br>
                <div class="text-danger">{{ contact_no_error_message }}</div>
                <label>Address: </label>
                <input type="text" name="address" :class="{ invalid : address_error }" v-model="customer_address" required><br>
                <div class="text-danger">{{ address_error_message }}</div>
                <div class="mt-4"> 
                    <button @click="updateCustomer()" class="btn btn-primary">Add</button>
                </div>
            </div>

How to save drop down Html form data into database using the following code?

This code is storing the data into php my admin database but i am not able to store the other fields excepts username and password.
so can anyone tell me the exact way how can i store the other fields using php?

only two fields are storing their data in database, username and password now i want to store the other fields too but i don’t know how to code it in php.
i am using wamp server .

and when i change some part of my code it will not store in the database. Please modify my curerent code so that i can perfectly run this small module.

Now that's all for this tutorial. Be sure to watch the video for good understanding.
    1. configure file contains the server and database name for references. 
       

<?php
/*
This file contains database configuration assuming you are running mysql using user "root" and password ""
*/

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'new_sample');

// Try connecting to the Database
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

//Check the connection
if($conn == false){
    dir('Error: Cannot connect');
}

?>


2. Register.php file through which we want to register the user and saving the details into the database.

<?php
require_once "configure.php";

$userName=$designation=$role= $password = $confirm_password = "";
$userName_err = $password_err = $confirm_password_err = "";

if ($_SERVER['REQUEST_METHOD'] == "POST"){

    // Check if userName is empty
    if(empty(trim($_POST['userName']))){
        $userName_err = "userName cannot be blank";
    }
    else{
        $sql = "SELECT id FROM users WHERE userName = ?";
        $stmt = mysqli_prepare($conn, $sql);
        if($stmt)
        {
            mysqli_stmt_bind_param($stmt, "s", $param_userName);

            // Set the value of param userName
            $param_userName = trim($_POST['userName']);

            // Try to execute this statement
            if(mysqli_stmt_execute($stmt)){
                mysqli_stmt_store_result($stmt);
                if(mysqli_stmt_num_rows($stmt) == 1)
                {
                    $userName_err = "This userName is already taken";
                }
                else{
                    $userName = trim($_POST['userName']);
                }
            }
            else{
                echo "Something went wrong";
            }
        }
    }

    mysqli_stmt_close($stmt);


// Check for password
if(empty(trim($_POST['password']))){
    $password_err = "Password cannot be blank";
}
elseif(strlen(trim($_POST['password'])) < 5){
    $password_err = "Password cannot be less than 5 characters";
}
else{
    $password = trim($_POST['password']);
}

// Check for confirm password field
if(trim($_POST['password']) !=  trim($_POST['confirm_password'])){
    $password_err = "Passwords should match";
}


// If there were no errors, go ahead and insert into the database
if(empty($userName_err) && empty($password_err) && empty($confirm_password_err))
{
    $sql = "INSERT INTO users (userName, password) VALUES (?, ?)";
    $stmt = mysqli_prepare($conn, $sql);
    if ($stmt)
    {
        mysqli_stmt_bind_param($stmt, "ss", $param_userName, $param_password);

        // Set these parameters
        $param_userName = $userName;
        $param_password = password_hash($password, PASSWORD_DEFAULT);

        // Try to execute the query
        if (mysqli_stmt_execute($stmt))
        {
            header("location: login_sample2.php");
        }
        else{
            echo "Something went wrong... cannot redirect!";
        }
    }
    mysqli_stmt_close($stmt);
}
mysqli_close($conn);
}

?>





<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>USER MASTER</title>
<link href='http://fonts.googleapis.com/css?family=Bitter' rel='stylesheet' type='text/css'>
<style type="text/css">
body{
    background:#AEE4FF;
}
.form-style-10{
    max-width:750px;
    padding:30px;
    margin:40px auto;
    background: #FFF;
    border-radius: 10px;
    -webkit-border-radius:10px;
    -moz-border-radius: 10px;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.13);
    -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.13);
    -webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.13);
}
.form-style-10 .inner-wrap{
    padding: 30px;
    background: #F8F8F8;
    border-radius: 6px;
    margin-bottom: 15px;
}
.form-style-10 h1{
    background: #2A88AD;
    padding: 20px 30px 15px 30px;
    margin: -30px -30px 30px -30px;
    border-radius: 10px 10px 0 0;
    -webkit-border-radius: 10px 10px 0 0;
    -moz-border-radius: 10px 10px 0 0;
    color: #fff;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.12);
    font: normal 30px 'Bitter', serif;
    -moz-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    -webkit-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    border: 1px solid #257C9E;
}
.form-style-10 h1 > span{
    display: block;
    margin-top: 2px;
    font: 13px Arial, Helvetica, sans-serif;
}
.form-style-10 label{
    display: block;
    font: 13px Arial, Helvetica, sans-serif;
    color: #888;
    margin-bottom: 15px;
}
.form-style-10 input[type="text"],
.form-style-10 input[type="date"],
.form-style-10 input[type="datetime"],
.form-style-10 input[type="email"],
.form-style-10 input[type="number"],
.form-style-10 input[type="search"],
.form-style-10 input[type="time"],
.form-style-10 input[type="url"],
.form-style-10 input[type="password"],
.form-style-10 textarea,
.form-style-10 select {
    display: block;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    -webkit-border-radius:6px;
    -moz-border-radius:6px;
    border: 2px solid #fff;
    box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.33);
    -moz-box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.33);
    -webkit-box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.33);
}

.form-style-10 .section{
    font: normal 20px 'Bitter', serif;
    color: #2A88AD;
    margin-bottom: 5px;
}
.form-style-10 .section span {
    background: #2A88AD;
    padding: 5px 10px 5px 10px;
    position: absolute;
    border-radius: 50%;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border: 4px solid #fff;
    font-size: 14px;
    margin-left: -45px;
    color: #fff;
    margin-top: -3px;
}
.form-style-10 input[type="button"],
.form-style-10 input[type="submit"]{
    background: #2A88AD;
    padding: 8px 20px 8px 20px;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    color: #fff;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.12);
    font: normal 30px 'Bitter', serif;
    -moz-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    -webkit-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    border: 1px solid #257C9E;
    font-size: 15px;
}
.form-style-10 input[type="button"]:hover,
.form-style-10 input[type="submit"]:hover{
    background: #2A6881;
    -moz-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.28);
    -webkit-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.28);
    box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.28);
}
.form-style-10 .privacy-policy{
    float: right;
    width: 250px;
    font: 12px Arial, Helvetica, sans-serif;
    color: #4D4D4D;
    margin-top: 10px;
    text-align: right;
}
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  padding: 12px 16px;
  z-index: 1;
}

.dropdown:hover .dropdown-content {
  display: block;
}
</style>
</head>

<body>

<div class="form-style-10">
<h1>New User Details<span>Kindly fill all details of new user</span></h1>
<form action=""  method="POST">
    <div class="section"><span>1</span>User Name</div>
        <div class="inner-wrap">
        <label>User Name <input type="text" name="userName" placeholder="Enter User Name" required/></label>
    </div>

    <div class="section"><span>2</span>Designation</div>
    <div class="inner-wrap">
          <label required>Designation</label>
            <div>
      <select name="designation" id="Post">
            <option value="Select Designation">Select Designation</option>
        <option value="Director">Director</option>
        <option value="Deputy Director">Deputy Director</option>
        <option value="Assistant Director">Assistant Director</option>
        <option value="SI-I">SI-I</option>
            <option value="SI-II">SI-II</option>
            <option value="DPA A">DPA A</option></select>
            <br><br>
        </div>

        </div>

    <div class="section"><span>3</span>Role and Rights &amp; Passwords</div>
        <div class="inner-wrap">
        <label>Role and Rights</label>
                <div>
            <select name="role" id="Role">
                <option value="Select Designation">Select Role</option>
                <option value="Admin">Admin</option>
                <option value="User">User</option></select>
                <br><br>
                <label>Password <input type="password" name="password" placeholder="Enter Your Password" required /></label>
                <label>Confirm Password <input type="password" name="confirm_password" placeholder="Again Enter Your Password" required /></label>
    </div>
    <div class="button-section">
     <input type="submit" name="Submit" >
    </div>
</form>
</div>

</body>
</html>

Show column with information in new column

I have a table here in this example with 2 order numbers under sub-orders. Now I need the info in the user_c_56 column in the sub-orders as well.

The aunr column is assigned to the order number. Here is the original table and the way I would like it to be.

original table

As she should be

Here my query:

SELECT b.order_nr,
       b.user_c_56,
       b.aunr,
       s.a_atufe,
       z.mehrfach_kz,
       b.soll_dauer
FROM [hydra1].[hydadm].[v_auftrags_zusatz] z
     JOIN [hydra1].[hydadm].[auftrags_bestand] b ON z.auftrag_nr = b.aunr
     JOIN [hydra1].[hydadm].[auftrag_status] s ON b.auftrag_nr = s.auftrag_nr
WHERE s.eingeplant = ('M');

WordPress Hook execute before pre_get_post

I load products based on cookie for that i need to check cookie exist or not before pre_get_post hook execute. i tried parse_query hook this i will work but execute multiple times on load. I write code after cookie create reload page, due to multiple exe i’ve got error ERR_TOO_MANY_REDIRECTS.

Kindly please advise.