-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
Did placing that new line in the function create the file? -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
Try outputting to a file then. (The file "rates_array_content.txt" should be created in the same folder as your script) function shipping_methods_based_on_wholesale_customer( $rates, $package ){ file_put_contents('rates_array_content.txt', print_r($rates, 1)); if( ! get_current_user_id() ) { 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; } -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
I was hoping it would be sent to your screen -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
It's your $rates array - the one you are using in the function that's being discussed all through this topic. Put the code I gave inside the function and post the out put to us. function shipping_methods_based_on_wholesale_customer( $rates, $package ){ echo '<pre>' . print_r($rates, 1) . '</pre>'; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if( ! get_current_user_id() ) { 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; } -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
With the code I've given you to output the $rates array -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
As requested some time ago... ...and still waiting. -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help
Something like this, maybe? function shipping_methods_based_on_wholesale_customer( $rates, $package ){ if( ! get_current_user_id() ) { 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; } -
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?