Woocommerce and php guru to help create array from woocommerce order object to be used to connect to external api
$10-30 USD
Completed
Posted over 2 years ago
$10-30 USD
Paid on delivery
All the woocommerce item meta is already done and being added to the order via checkout.
// Get order item meta.
$order = wc_get_order( $order_id );
// Get transaction id.
$transaction = $order->get_transaction_id();
// Get more order meta values
// Get via loop order item meta
foreach ( $order->get_items() as $itemId => $item ) {
// Product id.
$productId = $item->get_product_id();
// Product quantity.
$productQt = $item->get_quantity();
// with product id connect to api to get api product data. I have this working and I get 1 array json_encoded [{"Product":"api_id","value1":"1","value2":"2","quantity":"0"}]
$apiproduct = $api_result;
$apiproduct_decoded = json_decode( $apiproduct, true );
$remove_first_array = $apiproduct_decoded[0];
$product_Value1 = $is_product_controller[0]['value1'];
$product_Value2 = $is_product_controller[0]['value2'];
// Now I need to multiply array value 1 and value 2 by the woocommerce product quantity. These values are going to be used later to connect to api and send data.
$sum_value1 = $product_Value1 * $productQt;
$sum_value2 = $product_Value2 * $productQt;
// Now I need to rebuild original api result array with woocommerce quantity
$remove_first_array_change = array_replace($remove_first_array, ['Quantity' => $productQt]);
$rebuild_api_array = $remove_first_array_change;
// Get gift, returns true or false
$gift = wc_get_order_item_meta( $itemId, '_resource', gift );
// Get resource id from woocommerce. With the resource id
$resource = wc_get_order_item_meta( $itemId, '_resource', true );
}
All of the above is done and working. I need help with the last part.
To connect to the external api I need to make a loop one per unique woocommerce item meta $resource with a constructed body.
If I have 3 woocommerce products with the same $resource I need to combine all values. Maybe do this outside the final foreach?
foreach ( $resource as $uniqueresource ) {
// There's another value that comes from the external api the $resource_data. We need to get this value to include in the body for the last call and is based on the unique $resource.
// Since the loop is based on unique $resource I only need to get this value once per different $resource.... We are looping the $resource.
// I already have this call working.
$body = array(
'resource_data' => $resource_data,
'products' => array($rebuild_api_array, $rebuild_api_array, $rebuild_api_array,etc), like this [{"Product":"123","value1":"1","value2":"0","quantity":"7"},{"Product":"456","value1":"2","value2":"1","quantity":"2"},{"Product":"999","value1":"1","value2":"4","quantity":"6"} etc. last array can not have ending seperator coma or api returns error]
'sum_value1' => should be the sum of all $sum_value1,
'sum_value2' => should be the sum of all $sum_value2,
'gift' => if 1 resource $gift returns true then this setting is immediately true for all identical $resource,
);
// connect to api via POST
}
Hi
I can format your data to match the API request data. I CAN START RIGHT NOW.
Kindly contact me via chat to get started,. Looking forward to work on this.
Thank you so much
$30 USD in 1 day
5.0 (55 reviews)
5.6
5.6
13 freelancers are bidding on average $25 USD for this job
Hi there,
I am an experienced WordPress Designer/Developer with more than 8 years of experience. I will develop a fully functional Website with a sleek and minimal design to your specifications,
WordPress WooCommerce
WordPress E-Commerce
WordPress Speed-Optimization
WordPress Theme Customization
WordPress Plugin Customization
Thanks and regards,
Komal,
Hello,
We have reviewed the code structure and can easily help you to connect it to external API and will make a loop one per unique woo commerce item meta.
Kindly grant us the access to the store so we can start working and complete the task ASAP.
Waiting for your positive response!
Thanks,
Hello
I have read your request thoroughly & i can surely work on your project. However I have few questions to ask, are you available for a quick discussion?
Regards
*Web Developer and WordPress Expert*
Hi there
I have 6+ years of experience in Web Development Including PHP and HTML.
Please provide some information about your requirements so that I can understand your needs and start working together on completing your task soon.
Utilize my skills by hiring me. Contact me for further discussion.
Thank you
Pargat