Last active
October 7, 2018 15:29
-
-
Save tajulasri/382fab86b562355c979c2e70da63e238 to your computer and use it in GitHub Desktop.
wc order param dynamic handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$array = [ | |
'buy-1' => [ | |
'products' => [ | |
[ | |
'id' => 20, | |
'quantity' => 1 | |
] | |
] | |
] | |
]; | |
$params = 'buy-1'; | |
preg_match('@\w+-\d+@',$params,$matches); | |
if(isset($matches[0])) { | |
if(array_key_exists($matches[0],$array)) { | |
//add order | |
//loop product added | |
foreach($array[$matches[0]]['products'] as $product) { | |
echo "add product " . $product['id'] . " " . $product['quantity']; | |
} | |
} | |
else { | |
//product not found | |
//parameter data not found | |
echo "product not found."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment