-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
No. $is_wholesale = get_user_meta( 153, 'wholesale_customer', true ); -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
As the purpose of the function is to return "true" if the specified user is a wholesale customer, how do see that working? -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
It looks like get_user_meta() alway returns "false". You need to have a close look at that function's code to determine why. -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
Of course, it could be that the code is correct but the data says all your user are "wholesale" -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
Instead of $is_wholesale = get_user_meta( get_current_user_id(), 'wholesale_customer', true ); hard code the id values instead of "get_current_user_id()", so you use $is_wholesale = get_user_meta( 'A_USER_ID', 'wholesale_customer', true ); Test it substituting different ids. -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
Log in as different users and echo get_current_user_id() to see if outputs the correct ids for the logged in users * * * "no effect"??? Are you saying that no matter what id you specify, it always returns the same value? If that is the case then it would appear your problem is with the get_user_meta() function. -
Me too. I think a small but important operator like that gets lost without the whitespace.
-
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
Some questions for you Why is $package being passed to the function when it isn't used? Have you checked that get_current_user_id() is doing what its name suggests? Have you tested get_user_meta() with different existing ids to see if returns the correct is_wholesale value for them? Can you show us the contents of your $rates array ( echo '<pre>' . print_r($rates, 1) . '</pre>'; ) -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
I don't think that is the case, but the method seems convoluted. If I got it right, it could be rewritten as function shipping_methods_based_on_wholesale_customer( $rates, $package ){ $is_wholesale = get_user_meta( get_current_user_id(), 'wholesale_customer', true ); if( $is_wholesale ) { unset($rates['flat_rate:10'], $rates['flat_rate:7']); // To be removed for NON Wholesale users } else { unset($rates['flat_rate:13'], $rates['flat_rate:15']); // To be removed for Wholesale users } return $rates; } -
Time to do some reading here
-
Insert Randomly Generated name and surname into sqlite DB.
Barand replied to nickRSA's topic in PHP Coding Help
Look up sprintf in the manual to see how to use it properly. EDIT: I agree with @ginerjm - you should use a prepared query - it's easier than sprintf. $db->prepare("INSERT INTO info (name, surname) VALUES ( ?, ? ); $db->execute( [ $name, $surname ] ); -
select a.saint, b.url from the tables joined on a.saint = b.nom PS if you always want the a.saint value even if there is no matching b records, use a LEFT JOIN b
-
Can any body help me with this question. Have to do this in php
Barand replied to Athul's topic in PHP Coding Help
or $arr = [ 21, 12, 3 , 4, 25, 26, 14 ]; for ($i=0, $k = count($arr); $i<$k; $i++) { $left = array_sum(array_slice($arr, 0, $i)); $right = array_sum(array_slice($arr, 1+$i-$k)); if ($left == $right) $arr[$i] = "<sub>$left</sub><span style='font-weight: 600; color: red;'>$arr[$i]</span><sub>$right</sub>"; } echo join(', ', $arr); // show solution -
Can any body help me with this question. Have to do this in php
Barand replied to Athul's topic in PHP Coding Help
What have you tried so far? -
If that colour does exist it should probably be included with the other w3- classes and not out there on its own.
-
To use mysqli_query () you would need to have a mysqli connection, but that will only work with mysql databases (clue is in the name) and not with SQLite. You need to use the equivalent PDO method. $stmt = $db->prepare("INSERT into info(name,surname) values(?, ?)"); $stmt->execute( [ $firstname, $lastname ] );
-
My older version of TCPDF just collapsed like a house of cards when I tried and example page with PHPv8 throwing out errors everywhere - so that goes in the bin. As far as I know the newer versions use composer for installation. I did manage a sample using TFPDF Code <?php const ROOT = 'c:/inetpub/wwwroot'; require(ROOT.'/tfpdf/tfpdf.php'); include('db_inc.php'); $db = pdoConnect('exams'); $res = $db->query("SELECT name_en as en , name_ar as ar FROM staff ORDER BY RAND() LIMIT 10 "); $rows = $res->fetchAll(); class testpdf extends TFPDF { public function makePage($rows) { $this->AddPage(); $this->setFont('', '', 10); foreach ($rows as $r) { $this->SetFont('arial','',10); $this->Cell(60, 10, $r['en'], 'TB', 0, 'L'); $this->SetFont('calibri','',10); $this->Cell(60, 10, rtl($r['ar']), 'TB', 1, 'R'); } } } $test = new testpdf(); $test->AddFont('calibri','','calibri.ttf',true); $test->makePage($rows); $test->output(); function rtl($str) { $k = mb_strlen($str); for ($i=0; $i<$k; $i++) $a[] = mb_substr($str, $i, 1); $a = array_reverse($a); return join('', $a); } ?>
-
Then where are you holding the current value that you want to show as selected?
-
Something like this <select name="category"> <?php while ($category = mysqli_fetch_assoc($categories)) : $sel = $_GET['category']==$category['id'] ? 'selected' : ''; echo "<option $sel value='{$category['id']}'>{$category['title']}</option>"; endwhile; ?> </select>
-
FYI - my preferred method is not to use links with query strings but to add a hidden "page" field to the search form. When the pagination buttons are clicked they update the hdiden field with their page number and resubmit the form. Example (The table used is "pupil" table from my sql tutorial) <?php include 'db_inc.php'; // creates pdo connection $pdo = pdoConnect('jointute'); // use your own $searches_per_page = 5; $search = $_GET['search'] ?? ''; // set defaukt values $page = $_GET['page'] ?? 1; // // // Record count // $res = $pdo->prepare("SELECT COUNT(*) FROM pupil WHERE lname LIKE ? "); $res->execute(["%{$search}%"]); $number_of_pages = ceil($res->fetchColumn()/$searches_per_page); $prev = $page > 1 ? $page - 1 : 1; $next = $page < $number_of_pages ? $page + 1 : $number_of_pages; $start = max(1, $page - 2); $end = min($number_of_pages, $page + 2); // // Get data for display // $res = $pdo->prepare("SELECT fname , lname , classid , dob , timestampdiff(YEAR, dob, CURDATE()) as age FROM pupil WHERE lname LIKE ? ORDER BY lname, fname LIMIT ?,? "); $res->execute(["%{$search}%", ($page-1)*$searches_per_page, $searches_per_page ]); $pupils = ''; foreach ($res as $row) { $pupils .= "<tr><td>" . join("</td><td>", $row) . "</td></tr>" ; } ?> <!DOCTYPE html> <html lang='en'> <head> <title>Search example</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $().ready (function() { $(".paging").click( function() { let page = $(this).val() $("#page").val(page) // set page no in hidden form field $("#searchform").submit() // resubmit the form }) }) </script> <style type='text/css'> body { background-color: black; color: white; } td , th { padding: 4px; } </style> </head> <body> <form id='searchform'> Search for <input type='text' name='search' value="<?=$search?>"> <input type='hidden' name='page' id='page' value='<?=$page?>'> <input type='submit' value='Search'> </form> <?php if ($number_of_pages > 1) { echo "<br><br><button class='paging' value='$prev'><</button> "; for ($p = $start; $p <= $end; $p++) { echo "<button class='paging' value='$p'>$p</button> "; } echo "<button class='paging' value='$next'>></button>"; } ?> <br><br> <table border='1'> <tr><th>First Name</th><th>Last Name</th><th>Class</th><th>DOB</th><th>Student Age</th></tr> <?=$pupils?> </table> </body> </html>
-
Firstly, you need corectly formatted query stringd (you have another "?" before page= instead of a "&") Secondly you need to pass the search value (urlencodeed) and a submit value (1) echo '<a class="paging" href="?search='.urlencode($_GET['search']).'&submit=1&page=' . ($page + 1) . '">Forward</a>';
-
Try TCPDF. It's FPDF with lots of extras. I haven't tried it with Farsi but it handles Arabic well, unlike FPDF.
-
When you get to page 2, are $_GET['search'] and $_GET['submit'] both set?
-
How to count duplicated values in a table and display it?
Barand replied to imbruceter's topic in PHP Coding Help
$res is NOT an array, it is a result object. Therefore your loop never executes. Don't post pictures of code, post code.- 11 replies
-
- 1
-
-
- php
- phpmyadmin
-
(and 3 more)
Tagged with:
-
How to count duplicated values in a table and display it?
Barand replied to imbruceter's topic in PHP Coding Help
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $connection = mysqli_connect('localhost', '****', '****', '****'); $result = $connection->query("SELECT c.title , COUNT(p.category_id) as total FROM categories c LEFT JOIN posts p ON c.id = p.category_id GROUP BY c.id "); foreach ($result as $row) { echo "{$row['title']} : {$row['title']}<br>"; } Have you got error display on? If not, check your error log.- 11 replies
-
- php
- phpmyadmin
-
(and 3 more)
Tagged with: