Category Archives for webshop

Installeer WooCommerce

Installeer de volgende plugins:

  • WooCommerce
  • WooCommerce Autocomplete Orders
  • application passwords

In je functions.php plaats je de volgende code:

function mysite_woocommerce_order_status_completed( $order_id ) {
  error_log( "Order complete for order $order_id", 0 );

  $postUrl = 'https://requestb.in/rfq3q1rf';
  $order = wc_get_order( $order_id );
  $user = $order->get_user();
  if( $user ){
    // do something with the user
  }

  $data['order'] = $order->get_data();
  $data['user'] = $user;
  $jsonData = json_encode($data);

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $postUrl);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json']);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

  // receive server response ...
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $server_output = curl_exec ($ch);

  curl_close ($ch);
}
add_action( 'woocommerce_order_status_completed', 'mysite_woocommerce_order_status_completed', 10, 1 );