Skip to content

Commit

Permalink
Merge pull request #4 from kabisa/2nd-webhook
Browse files Browse the repository at this point in the history
2nd webhook
  • Loading branch information
timoj authored Mar 27, 2018
2 parents 9ab4b5d + 849997b commit 8462331
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions includes/wcwuunder-export-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function check_phone() {
(Gebruik de opmaak: +31612345678)</label>
<input type="text" class="form-control input-sm" name="data[phone_number]"
id="wuunderPhonenumber"
value="<?php echo((empty($row['telefoon']) || strcmp($row['telefoon'], "+31") === 0) ? "+31628307244" : $row['telefoon']); ?>"
value="<?php echo((empty($row['telefoon']) || strcmp($row['telefoon'], "+31") === 0) ? "" : $row['telefoon']); ?>"
required="">
</div>
</div>
Expand Down Expand Up @@ -405,4 +405,4 @@ class="button-wuunder btn save_order btn-primary tips">
</fieldset>
<?php endforeach; ?>

</form>
</form>
34 changes: 23 additions & 11 deletions woocommerce-wuunder.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,31 @@ public function webhook()
$orderId = $_REQUEST['order'];
$bookingToken = $_REQUEST['token'];
$data = json_decode(file_get_contents('php://input'), true);
$errorRedirect = true;

$orderBookingToken = get_post_meta($orderId, '_wuunder_label_booking_token')[0];
if ($bookingToken === $orderBookingToken) {
if (!empty($data['shipment']['id']) || !empty($data['shipment']['track_and_trace_url']) || !empty($data['shipment']['label_url'])) {
update_post_meta($orderId, '_wuunder_label_id', $data['shipment']['id']);
update_post_meta($orderId, '_wuunder_track_and_trace_url', $data['shipment']['track_and_trace_url']);
update_post_meta($orderId, '_wuunder_label_url', $data['shipment']['label_url']);

$order = new WC_Order($orderId);
$order->update_status(get_option("wc_wuunder_post_booking_status"));
}
} else {
wp_redirect("", 500);
if ($data['action'] === "shipment_booked") {
if ($bookingToken === $orderBookingToken) {
if (!empty($data['shipment']['id']) || !empty($data['shipment']['track_and_trace_url']) || !empty($data['shipment']['label_url'])) {
update_post_meta($orderId, '_wuunder_label_id', $data['shipment']['id']);
update_post_meta($orderId, '_wuunder_track_and_trace_url', $data['shipment']['track_and_trace_url']);
update_post_meta($orderId, '_wuunder_label_url', $data['shipment']['label_url']);

$order = new WC_Order($orderId);
$order->update_status(get_option("wc_wuunder_post_booking_status"));
$errorRedirect = false;
}
}
} elseif ($data['action'] === "track_and_trace_updated") {
// This is the 2nd webhook
$order = wc_get_order($orderId);
$note = __("Het pakket is aangemeld bij: ". $data["carrier_name"] ."\n De track and trace code is: ".$data["track_and_trace_code"]);
$order->add_order_note($note);
$order->save();
$errorRedirect = false;
}

if($errorRedirect){wp_redirect("", 500);}
}

}
Expand Down

0 comments on commit 8462331

Please sign in to comment.