Fixed shortcode download button for all digital product WooCommerce [duplicate]

I’m using woocommerce and have “virtual” and “downloadable” products. I want to create a shortcode to display a “Download” button for these products. Because there are so many products, I want to have a fixed shortcode to use for all products, not shortcode like [download id=”123″].

I tried using this code and use [download_button] in short descreption but it doesn’t work

function download_button_shortcode( $atts ) {
    global $product;
    $download_files = $product->get_downloads();
    $download_url = isset( $download_files[0]['file'] ) ? $download_files[0]['file'] : '';
    $button = '<a href="' . esc_url( $download_url ) . '" class="button">Download</a>';
    return $button;
}

add_shortcode( 'download_button', 'download_button_shortcode' );

cansome one help me connect the php to my sql? [duplicate]

Fatal error: Uncaught Error: Class “mysqli” not found in
C:xampphtdocsStudy Spacedata.php:10 Stack trace: #0 {main} thrown
in C:xampphtdocsStudy Spacedata.php on line 10

How to fix it? I already delete what some of you told me – I already removed the ; tag. Can some one help me?

Some say delete XAMPP but I can’t delete it because some of my important files are in there.

Can I typehint a php enum?

I want to refactor my codebase from MyCLabs Enums to PHP’s native enum’s. I’m already running into a few small issues:

  1. How can I typehint that an argument or return type must be an enum?
  2. How can I check if a value is an enum?

The best I can do with regards to typehinting is typehinting object.
The best I can do for checking if a value is an enum is with with a ReflectionClass, eg:

if (
    is_object($value)
    && (new ReflectionClass($value))->isEnum()
) {
    // it's an enum.
}

Without these simple checks, it feels like refactoring to native enums is a step backwards. Am I approaching it incorrectly?

Laravel 8.75 doesn’t convert custom rule into a message

I am using Laravel 8.75 and I want to validate fields. I have created a custom rule to validate money.

The rule looks like this:

<?php

namespace AppRules;

use IlluminateContractsValidationRule;

class FlexibalCurrencyRule implements Rule
{
    private $regex = '/^([0-9]{1,10})([.,][0-9]{1,2})?$/';

    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return preg_match($this->regex, $value);
    }

    /**
     * Get the validation error message.
     *
     * @return string | array
     */
    public function message()
    {
        return "currency";
    }
}

It is very plain and simple. Then in my controllers I do the following:

$requestDto = json_decode($request->getContent(), true);

$validator = Validator::make($requestDto, [
    'name' => 'required|max:100',
    'price' => ['required', new FlexibalCurrencyRule],
]);

if ($validator->fails()) {
    // Send response to browser
}

When I call the endpoint my validation messages contain the following:

    "price": {
        "App\Rules\FlexibalCurrencyRule": []
    }

As you can see Laravel doesn’t call the message() function. It just prints the class name. From what I understand it should call the message() function and return ‘currency’ as the validation rule. How can I convert a custom rule into a string message instead of the class name being returned?

extra numbers attached to my values (PHP) [duplicate]

I’m facing a very odd phenomenon when trying to separate the whole numbers and decimals from a float value.

<?php

echo "<br>" . numToWords(1004712896.17);

function numToWords($value) : String
{   
    // $words is used to store the translated string
    $words = "";
    print "<br>VALUE: $value";
    $whole = floor($value);
    print "<br>WHOLE: $whole";    
    $deci = $value - $whole;
    print "<br>DECI: $deci";

    // continue to translate numbers into words
    ...
    return $words;
}

The out put shows the decimal part having some extra numbers attached at the end:

VALUE: 1004712896.17
WHOLE: 1004712896
DECI: 0.16999995708466001004712896

I noticed that the last 12 numbers are the whole-number part of my value. Also, it is not 0.17 as what I entered, but is 0.1699999…

I can get back 17 if I multiply it by 100 and ceil() the result, but still, the extra numbers are present in my result:

$deci = ceil(($value - $whole) * 100);

the output:

DECI: 17001004712896

So… What have I done wrong? I don’t think memory corruption is the cause as I tried to close the tab and re-open it, and even closed my browser and re-open it, the problem persists. And memory overflow is not the problem, since nothing changed even after I’ve reduced the value to the range of thousands.

Is there something I must do before performing any calculation to prevent this, or is this a bug of PHP?

Using XAMPP Version 8.0.30 on FireFox (Latest).

Edit:

trying another method, by using the string equivalent of the value, and then locate the position of the period, and separate the 2 parts into 2 strings, still, the extra numbers are attached to the substring, even when I specifically said I only want 2 characters for my decimal string:

$valstr = strval($value);
print "<br>VALSTR: $valstr";
$pos = strpos($valstr, ".", 0);
$intstr = substr($valstr, 0, $pos);
$decstr = substr($valstr, $pos+1, 2);
print "<br>POS: $pos";
print "<br>IntStr: $intstr";
print "<br>DecStr: $decstr";

output:
VALSTR: 8712896.34
POS: 7
IntStr: 8712896
DecStr: 34008712896 // supposed to be 34 only

I’m starting to think this is a bug in PHP…

RubixML model always return the same prediction in PHP

I’m trying to extract the product price for different sentences using https://rubixml.com/, but it always returns 260, the first label I give to it

<?php
include_once '../vendor/autoload.php';

use RubixMLDatasetsLabeled;
use RubixMLDatasetsUnlabeled;
use RubixMLClassifiersKNearestNeighbors;
use RubixMLTransformersWordCountVectorizer;
use RubixMLTransformersTfIdfTransformer;
use RubixMLPipeline;
use RubixMLExtractorsCSV;

$samples= ['The price is 260','The cost is 500','This shirt costs 300','The value of this item is 450','Sold for 150 dolars'];
$labels = ['260',             '500',            '300',                 '450',                           '150'];

$dataset = new Labeled($samples, $labels);

// genrate the model
$pipeline = new Pipeline([
    new WordCountVectorizer(100),
    new TfIdfTransformer(),
], new KNearestNeighbors(3));

// training with dataset
$pipeline->train($dataset);

// analize new frace
$new = Unlabeled::build([
    ['Price: 1200'],
]);

// Predict
$predictions = $pipeline->predict($new);
var_dump($predictions);

I have changed the values for the KNearestNeighbors, provide larger inputs for train dataset, change the Vectorizer. But nothing changes.

In PHP, how to recurse through a Closure when the variable name holding the anonymous function is a variable-variable

I have a list of about 100 articles, and within each article is a list of clauses. The clauses are a list of varying levels deep.

$clauses = array(
  [
    'Fields' => ['Clause' => 'clause 1', 'Status' => 'Draft']
  ],
  [
    'Fields' => ['Clause' => 'clause 2', 'Status' => 'Draft'],
    'SubClauses' => [
      [
        'Fields' => ['Clause' => 'clause 2_a', 'Status' => 'Draft'],
        'SubClauses' => [
          [
            'Fields' => ['Clause' => 'clause 2_a_1', 'Status' => 'Draft']
          ],
          [
            'Fields' => ['Clause' => 'clause 2_a_2', 'Status' => 'Draft']
          ]
        ]
      ]
    ]
  ],
  [
    'Fields' => ['Clause' => 'clause 3', 'Status' => 'Draft']
  ]
);

echo PHP_EOL;

To create an html ordered list out of the $clauses array, I built this:

function htmlList ( $clauses, $depth = 0 ) {
  
  if ( $depth == 0 ) {
    echo '<ol type="1">';
  } elseif ( $depth == 1 ) {
    echo '<ol type="i">';
  } else {
    echo '<ol type="a">';
  }
  
  foreach ( $clauses as $key => $clause ) {
    if ( isset($clauses[$key]['SubClauses']) ) {
      echo '  <li>' . $clauses[$key]['Fields']['Clause'];
      htmlList ( $clauses[$key]['SubClauses'], ++$depth );
    } elseif ( isset($clauses[$key]['Fields']) ) {
      echo '  <li>' . $clauses[$key]['Fields']['Clause'] . '</li>';
    }
  }
  
  $depth--;
  echo '  </li>';
  echo '</ol>';
}

htmlList ( $clauses );

echo PHP_EOL;

It only builds the list for a single article. When the code loops to the next article, i get a error because the function is already defined.

I want to keep the html in the template and not put it inside the code files, so I have the function in the template where it can write the html there.

I need to make the name of the function change when the next article loops, so I converted this to a closure and assigned it to a variable. I am passing the function since I need it to recurse.

$htmlList = function ( $clauses, $depth = 0 ) use ( &$htmlList ) {
  
  if ( $depth == 0 ) {
    echo '<ol type="1">';
  } elseif ( $depth == 1 ) {
    echo '<ol type="i">';
  } else {
    echo '<ol type="a">';
  }
  
  foreach ( $clauses as $key => $clause ) {
    if ( isset($clauses[$key]['SubClauses']) ) {
      echo '  <li>' . $clauses[$key]['Fields']['Clause'];
      $htmlList ( $clauses[$key]['SubClauses'], ++$depth );
    } elseif ( isset($clauses[$key]['Fields']) ) {
      echo '  <li>' . $clauses[$key]['Fields']['Clause'] . '</li>';
    }
  }
  
  $depth--;
  echo '  </li>';
  echo '</ol>';
};

$htmlList ( $clauses );

echo PHP_EOL;

This also works for a single article, but allows the name to be changed dynamically. I then made the name of the variable that holds the name of the function dynamic.

$articles = array(
    ['Title' => 'title 1', 'Status' => 'Draft'],
    ['Title' => 'title 2', 'Status' => 'Draft'],
);

for ( $i = 0; $i < sizeof($articles); $i++ ) {
  
  echo $articles[$i]['Title'] . PHP_EOL;
  
  $htmlList = 'htmlList' . '_' . $i;
  $$htmlList = function ( $clauses, $depth = 0 ) use ( &$$htmlList ) {
    
    if ( $depth == 0 ) {
      echo '<ol type="1">';
    } elseif ( $depth == 1 ) {
      echo '<ol type="i">';
    } else {
      echo '<ol type="a">';
    }
    
    foreach ( $clauses as $key => $clause ) {
      if ( isset($clauses[$key]['SubClauses']) ) {
        echo '  <li>' . $clauses[$key]['Fields']['Clause'];
        $$htmlList ( $clauses[$key]['SubClauses'], ++$depth );
      } elseif ( isset($clauses[$key]['Fields']) ) {
        echo '  <li>' . $clauses[$key]['Fields']['Clause'] . '</li>';
      }
    }
    
    $depth--;
    echo '  </li>';
    echo '</ol>';
  };
  
  $$htmlList ( $clauses );
  
}

This is where it breaks. It does not like variably named function name inside the use() and errs at the $$ because it is a variable-variable and it only allows 1 $ and I have 2 $$ since the variable name’s value changes.

Would it be better to save the function in the main code outside the template so it doesn’t have to build anew for each article, or would it better to put the function in the template and keep html out of the main code files? All other constructs surrounding html are generally in the template files.

How can I get the clauses to convert to an html list for each article it loops through?

Getting Serialization of ‘Closure’ is not allowed when trying to dispatch a job

I’m new to php and laravel and I’m attempting to dispatch a job when one of my models is created, but when I try to dispatch the job, I get the error “Serialization of ‘Closure’ is not allowed”, which is confusing to me because I would have thought that I needed to pass in an anonymous function to get that error.

I have an observer that watches the created event for my order model.

<?php

namespace AppObservers;

use AppModelsOrder;
use AppJobsCreateOrderTasks;

class OrderObserver
{
    /**
     * Handle the Order "created" event.
     */
    public function created(Order $order): void
    {
        CreateOrderTasks::dispatch($order);
    }
    ...etc

}

And I have my job

    <?php
    
    namespace AppJobs;
    
    use IlluminateContractsQueueShouldQueue;
    use IlluminateFoundationQueueQueueable;
    use AppModelsOrder;
    use IlluminateFoundationBusDispatchable;
    use IlluminateQueueInteractsWithQueue;
    use IlluminateQueueSerializesModels;
    use IlluminateSupportFacadesLog;
    
    class CreateOrderTasks implements ShouldQueue
    {
        use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
        protected Order $order;
    
        public function __construct(Order $order)
        {
            $this->order = $order;
        }
    
        /**
         * Execute the job.
         */
        public function handle(): void
        {
                Log::info('Order retrieved:', ['order' => $this->order]); // Log the order details
        }
    }

I’ve also tried passing in just the order id and updating the job e.g.

CreateOrderTasks::dispatch($order->id);

But I still get the same error. What am I doing wrong?

Got error – failed to open stream: no suitable wrapper could be found

Other similar posts did not fix this error.
Using Codeigniter and Openai API to generate images.
Started getting this error after server migration.
Now it just places 0 byte img file on the server and throws this error.
It was 3MB images before, not huge.

A PHP Error was encountered
Severity: Warning
Message: file_get_contents(https://oaidalleapiprodscus.blob.core.windows.net/private/org-vsNFQNxeX6XH5mkcucSgjmwr/user-xrjvRzlnKwWRfjibOKWJRpd6/img-3VQ4qjdmWfizq6mWRGRl7TgI.png?st=2024-09-28T13%3A24%3A34Z&se=2024-09-28T15%3A24%3A34Z&sp=r&sv=2024-08-04&sr=b&rscd=inline&rsct=image/png&skoid=d505667d-d6c1-4a0a-bac7-5c84a87759f8&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-09-28T00%3A48%3A37Z&ske=2024-09-29T00%3A48%3A37Z&sks=b&skv=2024-08-04&sig=6zC7Ix2wBA3L1Bn9OYW%2BeE%2BX5svP0AsRjm%2BTe%2BbobNo%3D): failed to open stream: no suitable wrapper could be found
Filename: controllers/Images.php
Line Number: 599
Backtrace:
File: /home/rztxdnnj/public_html/app/application/controllers/Images.php
Line: 599
Function: file_get_contents
File: /home/rztxdnnj/public_html/app/index.php
Line: 316
Function: require_once

Tryd the image link, its working

allow_url_fopen and file_get_contents are On

Images.php:

  public function ai_image_generator(){
        $keys_words = '';
        if(isset($_POST['key_words'])):
        $keys_words = html_escape($_POST['key_words']);
        endif;
        $image_size = '';
        if(isset($_POST['image_size'])):
        $image_size = html_escape($_POST['image_size']);
        endif;
        $ogj = str_replace(" ","%20",$keys_words);
        if(!empty($image_size)){
            $size = $image_size;
        }else{
            $size = "1024x1024";
        }
        if(!empty($ogj)){
            $args = array(
                "prompt" => $ogj,
                "n"=>1,
                "size"=>$size,
                'model'  => 'dall-e-3'
            );

        $data_string = json_encode($args);
        $ch = curl_init('https://api.openai.com/v1/images/generations');
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer '.AI_IMAGES_CODE
        'Content-Type: application/json'
        ));
        $result = curl_exec($ch);
        $httpcode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
        $a = json_decode($result,true);
            if(isset($a['data'])){
                foreach($a['data'] as $a_child){
                    $image_path = 'openai_images'.rand(10,100);
                    $img = 'uploads/ai/'.$image_path.'.png';
                    $imgUrl = $a_child['url'];
                    file_put_contents($img, file_get_contents($imgUrl));
                    $img_url= base_url().'/uploads/ai/'.$image_path.'.png';
                    echo '<div data-url="'.$img_url.'"><img src="'.$img_url.'" alt="AI IMAGES"></div>';
                }
            }else{
                echo '<p>'.esc_html($a['error']['message']).'</p>';
            }
        }else{
            echo '<p>'.esc_html__('Please Enter Object Name.','gpt-blaster').'</p>';
        }


      die();
    }

I donot own the server, i am not sure what they did or did nothing at all to solve this. But what am sure off that allow_url_fopen and file_get_contents are On.

SQL Query returning values in phpMyAdmin but not in PHP PDO code [duplicate]

I’m working on an assignment to create a management system for a high school bus transport system. Everything has been going swimmingly until now, for some reason, I cannot access the “learner_trips” (the table where trip information for every learner is stored) table.

I’m trying to access a learner’s trip information, display said information for an admin of the system, and allow the admin to email the learner’s parent with that trip information or allow said admin to remove the learner from the table.

But all I get is this error:

Warning: Trying to access array offset on value of type bool in C:xampphtdocsstorsviewadmin_lists.php on line 146

Now I understand that the error probably means the PDO function I’m using for this is returning false. But the same query in that function works and returns what it should when I put it into phpMyAdmin with an ID.

I haven’t encountered such an error anywhere else in my code or tables.

I’ve tried changing the query in the function to use implicit joins instead of INNER JOINs, I tried casting the ID gotten through POST to integers, but nothing works. I get the same error. I’ve looked at some other questions here on SO related to my problem, but none of them address my problem.

Here’s an example of what the query should return in PHP PDO, after running in phpMyAdmin:

Example of SQL query in phpMyAdmin

My related code in index.php:

        case "send_trip_info":
            // Send email with trip info to parent
            // get input
            $l_id = filter_input(INPUT_POST, "l_id");
            
            // Get trip info and parent
            $info = getPassengerInfo($l_id);
            $parent_id = get_parent_id($l_id);
            $parent_info = get_parent_info($parent_id);
            $to_name = $parent_info["name"];
            $to = $parent_info["email"];
            $name = $learners[$l_id]["name"];
            $p1_name =  $info["p1_name"];
            $p1_time =  $info["p1_time"];
            $p2_name =  $info["p2_name"];
            $p2_time =  $info["p2_time"];

            // body
            $body = "Dear $to_name, <br><br> Here is the trip information for $name: <br><br>
                <b>Pickup Point and Time</b>: $p1_name at $p1_time<br>
                <b>Dropoff Point and Time</b>: $p2_name at $p2_time<br>
                <br>
                Kind Regards<br>
                Strive High
            ";
            $alt = "Dear $to_name, nn Here is the trip information for $name: nn
                PICKUP Point and Time: $p1_name at $p1_timen
                DROPOFF Point and Time: $p2_name at $p2_timen
                n
                Kind Regardsn
                Strive High
            ";

            send_mail("STORS Trip Info For $to_name", $body, $alt, $to, $to_name);
        break;

I’ve also received the same kind of error in the “get info and parent” section of the code above.

<!-- Passenger List (learner_trips table) -->
                 <div class="learner_section" id="passengerList">
                    <div class="mb-3 table-responsive">
                                    <!-- Passenger List table here -->
                                    <table class="table table-primary table-striped table-bordered">
                                            <thead>
                                                <tr>
                                                    <th>Learner Name</th>
                                                    <th>Pickup Point</th>
                                                    <th>Pickup Time</th>
                                                    <th>Dropoff Point</th>
                                                    <th>Dropoff Time</th>
                                                    <th colspan="2">Options</th>
                                                </tr>
                                            </thead>
                                            <tbody id="pass_list">
                                                <?php for ($i = 0; $i < count($learners); $i++): ?>
                                                    <?php if (checkLearnerPassengerStatus($learners[$i]['id'])) : ?>
                                                        <?php $info = getPassengerInfo($learners[$i]["id"]); ?>
                                                        <tr>
                                                            <td name="fullName"><?php echo $learners[$i]["name"] . " " . $learners[$i]["surname"] ?></td>
                                                            <td name="p1_point_name"><?php echo $info["p1_name"] ?></td>
                                                            <td name="p1_pickup_time"><?php echo $info["p1_time"] ?></td>
                                                            <td name="p2_point_name"><?php echo $info["p2_name"] ?></td>
                                                            <td name="p2_dropoff_time"><?php echo $info["p2_time"] ?></td>
                                                            <td>
                                                                <button class="btn btn-danger" value="<?php echo $info['id'] ?>" name="cancelPassBtn">Remove From List</button>
                                                            </td>
                                                            <td>
                                                                <form method="POST">
                                                                    <input hidden name="action" value="send_trip_info"/>
                                                                    <input hidden name="l_id" value="<?php echo $learners[$i]['id'] ?>"/>
                                                                    <button class="btn btn-success" type="submit" name="emailBtn">Email Trip To Parent</button>
                                                                </form>
                                                            </td>
                                                        </tr>
                                                    <?php endif; ?>
                                                <?php endfor; ?>
                                            </tbody>
                                    </table>

The code above is from admin_lists.php where the error appears.

Here’s my code from my PDO function:

    // Get a learner's passenger info
    function getPassengerInfo($id)
    {
        global $db;
        $query = "SELECT id, t1.point_name AS p1_name, t1.pickup_time AS p1_time, t2.point_name AS p2_name, t2.dropoff_time AS p2_time FROM learner_trips 
        INNER JOIN route_points AS t1 ON t1.point_num = learner_trips.pickup_id 
        INNER JOIN route_points AS t2 on t2.point_num = learner_trips.dropoff_id WHERE learner_id = :id";
        $statement = $db->prepare($query);
        $statement->bindValue(":id", $id);
        $result = $statement->fetch();
        $statement->closeCursor();
        return $result;
    }

My full code is available in this git repo: https://github.com/moppdev/ICT3715_STORS_PROJECT

I’m not sure what I could be doing wrong? Theoretically, everything should be firing but for some reason it just refuses to? I’m not getting any other database related errors either… This error has been driving me crazy for the past two days…

Limit only shipping states (provinces) but not billing states in WooCommerce

I have the following code which limits the provinces to Valencia (Spain) only, in WooCommerce:

add_filter( 'woocommerce_states', 'tl45r_custom_woocommerce_states' );

function tl45r_custom_woocommerce_states( $states ) {

    // Only show specific provinces (Madrid - MD and Barcelona - B) for Spain (ES)
    $states['ES'] = array(
        //'MD' => __( 'Madrid', 'woocommerce' ),
        //'B'  => __( 'Barcelona', 'woocommerce' ),
        'V'  => __( 'Valencia', 'woocommerce' ),
    );

    return $states;
}

However, I want this limitation only be applied to the shipping field but not the billing field.

How can I do this?

PHP Session Causing Page To Not Load

This is a bug seen on the production server. On dev instance the code seems to be working just fine. Infact, in multiple different AWS instances the code is running just fine.

The Bug:
On loading a specific page that’s pageA.php, the session is getting problematic. Before trying to load pageA.php all other pages are loading perfectly fine. But as soon as I load the page pageA.php, all other PHP pages stop loading. ( keeping loading for 5 min+ ) & at show HTTP 503 error.

currently pageA.php is loading a lot of values into session for quick referencing data. & is infact working just find on all other AWS instances.

I’ve tried restarting the IIS server. Again same story, all pages load fine, until I load pageA.php. Then everything stops loading with the 503 error.

Checked server machine for load, CPU at 2-5% & Memory at 10% utilization. So doesn’t seem to be any kind of heavy load on the system either.

Tried destroying & recreating session in another PHPfile.

<?php

session_start();
session_destroy();
session_start();

// Check if there are any session variables set
if (!empty($_SESSION)) {
    echo '<table border="1" cellspacing="0" cellpadding="10">';
    echo '<tr><th>Session Index</th><th>Value</th></tr>';
    
    // Loop through each session variable and print its index and value
    foreach ($_SESSION as $index => $value) {
        echo '<tr>';
        echo '<td>' . htmlspecialchars($index) . '</td>';
        echo '<td>' . htmlspecialchars(print_r($value, true)) . '</td>';
        echo '</tr>';
    }

    echo '</table>';
} else {
    echo 'No session variables are set.';
}

?>

But even this file refused to load & goes to HTTP 503.

I’ve removed the session_start() & all other related code, just tried

echo " Hello ";

Works just fine. So my diagnosis is something is wrong with session, but can’t figure out how to debug it or what the issues exactly is. Can’t share code due to confidentiality. Any help in debugging is appreciated.

LiveWire v3 Dispatch Method Does Not Show Bootstrap Modal In Laravel v11

I’m working with Laravel v11 and wanted to show a Modal on users list blade when clicking on Add New Button:

<div class="card-header">
   <div class="card-tools">
      <button type="button" wire:click="addNew">Add New</button>
   </div>
</div>

And this is AppLivewireAdminUsersListUsers Class:

class ListUsers extends Component
{
    public $users;
    public $name;
    public $email;

    public function mount()
    {
        // Fetching users from the database
        $this->users = User::all();
    }

    public function addNew()
    {
        // Trigger modal open event
        $this->dispatch('showModal');
    }

    public function save()
    {
        // Save logic
        User::create([
            'name' => $this->name,
            'email' => $this->email,
        ]);

        // Reset input fields
        $this->reset('name', 'email');

        // Close the modal after saving
        $this->dispatch('closeModal');
    }

    public function render()
    {
        return view('livewire.admin.users.list-users')->layout('layouts.app');
    }
}

But now when clicking on Modal, I get this at Console Bar and nothing appears as Modal:

capture

So what’s going wrong here? How can I show the Modal properly in this case?

Note that I’m using “livewire/livewire”: “^3.5”

And here is the script in `list-users` blade:

<script>
    document.addEventListener('livewire:load', function () {
        Livewire.on('showModal', () => {
            const modal = document.getElementById('myModal');
            if (modal) {
                modal.style.display = 'block'; // Show the modal
            }
        });

        // Close modal when the close button is clicked
        document.addEventListener('click', function (event) {
            const modal = document.getElementById('myModal');
            if (event.target.classList.contains('close')) {
                modal.style.display = 'none'; // Hide the modal
            }
        });
    });
</script>

From version 8.1 to version 8.2 start laragon has this error

From version 8.1 to version 8.2 start laragon has this error

httpd.exe - Entry point not found

Procedure entry point
Cannot find nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation in dynamic link library C:laragonbinphpphp-8.2.24-Win32-vs16-x64

What is the cause of this error, and how can I prevent it?

Display “Free Shipping” for WooCommerce Cart Products with Zero Shipping Cost

I’m trying to display “Free Shipping” for products in the WooCommerce cart that have a shipping cost of 0. I am using Webiwork Shipping Per Product WooCommerce plugin to add per-product shipping, and I want to show this message only for those products, while leaving products with non-zero shipping charges unchanged, like this screenshot:

like this screenshot

I attempted to use the following code:

add_action('woocommerce_after_cart_item_name', 'display_free_shipping_for_cart_items', 20, 2);
function display_free_shipping_for_cart_items($cart_item, $cart_item_key) {
    $packages = WC()->shipping->get_packages();

    foreach ($packages as $package) {
        if (isset($package['contents'][$cart_item_key])) {
            $product = $package['contents'][$cart_item_key];

            if (!empty($package['rates'])) {
                $shipping_rate = reset($package['rates']);
                $shipping_cost = $shipping_rate->cost;

                if ($shipping_cost == 0) {
                    echo '<p class="product-shipping-cost">Free Shipping</p>';
                }
            }
        }
    }
}

But it seems to either show nothing or doesn’t work as expected.