Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Did placing that new line in the function create the file?
  2. 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; }
  3. I was hoping it would be sent to your screen
  4. 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; }
  5. With the code I've given you to output the $rates array
  6. As requested some time ago... ...and still waiting.
  7. 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; }
  8. No. $is_wholesale = get_user_meta( 153, 'wholesale_customer', true );
  9. As the purpose of the function is to return "true" if the specified user is a wholesale customer, how do see that working?
  10. It looks like get_user_meta() alway returns "false". You need to have a close look at that function's code to determine why.
  11. Of course, it could be that the code is correct but the data says all your user are "wholesale"
  12. 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.
  13. 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.
  14. Me too. I think a small but important operator like that gets lost without the whitespace.
  15. 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>'; )
  16. 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; }
  17. Time to do some reading here
  18. 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 ] );
  19. 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
  20. 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
  21. If that colour does exist it should probably be included with the other w3- classes and not out there on its own.
  22. 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 ] );
  23. 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); } ?>
  24. Then where are you holding the current value that you want to show as selected?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.