February 15th, 2017, 04:42 AM
Merging two functions
I'm Michele and I'm from Italy.
I started coding a few weeks ago and I'm still a novice in this field, so I hope to get help from those who have more experience than me to learn something new!
My problem is this:
I am creating an ecommerce based on WordPress and I'm trying to automate the whole phase of import of products through WP All Import.
I could fit almost anything and I miss only this small piece. As you can see from the picture below, the "calet" field is imported with a comma and a zero, and this creates import problems. Besides eliminating ",0" from that field should I do also another operation. The "calet" field must always be 3 digits, so if for example I have a value of "12" has to become "012", if I have a value of "5" should be "005" and if I have a value of "125" it will remain unchanged.
I wrote the following function but does not seem to work, what is wrong?
Are days that I try to solve this problem but I can't... I thank in advance anyone who can help me out!
$quantity = trim($var);
$quantity = str_replace(",0", '', $quantity);
return intval($var) . '';
$lunghezza = strlen($var);
if($lunghezza == 3)
if($lunghezza == 2)
$var = '0'.$var;
if($lunghezza == 1)
$var = '00'.$var;
return $var ;
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!