Skip to content

Instantly share code, notes, and snippets.

@tajulasri
Last active October 7, 2018 15:29
Show Gist options
  • Save tajulasri/382fab86b562355c979c2e70da63e238 to your computer and use it in GitHub Desktop.
Save tajulasri/382fab86b562355c979c2e70da63e238 to your computer and use it in GitHub Desktop.
wc order param dynamic handler
$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