Woocommerce and php guru to help create array from woocommerce order object to be used to connect to external api

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


Compétences : PHP, WordPress, WooCommerce

En voir plus : screen scrape create array php, create invoice woocommerce, woocommerce php grouped products, create account woocommerce, create account woocommerce wordpress, woocommerce php, woocommerce php 7, create custom woocommerce shop page, woocommerce.php not working, create product woocommerce api, create custom woocommerce theme, woocommerce php api, woocommerce php version, woocommerce php github, automatic woocommerce php, woocommerce.php example, create invoice woocommerce frontend, woocommerce subscriptions create pending renewal order, create pending renewal order woocommerce

Concernant l'employeur :
( 1 commentaire ) Estoril, Portugal

Nº du projet : #31746738

Décerné à:


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

%selectedBids___i_sum_sub_4% %project_currencyDetails_sign_sub_5% USD en 1 jour
(55 Commentaires)

13 freelances font une offre moyenne de 25 $ pour ce travail

(128 Commentaires)
(142 Commentaires)
(125 Commentaires)

I checked the requirements . I just want to discuss few more things. I am available to discuss now. Waiting for your response. Thanks.

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(52 Commentaires)

I have some questions regarding the specifications of the project. Could we please have a chat? My Skills: WooCommerce, PHP and WordPress

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 7 jours
(92 Commentaires)

I can start right now... Hi, I have been working on WordPress since last 8+ years. My previous reviews and portfolio are uploaded on my profile. Please check it's my portfolio: [login to view URL] I'm interested Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(72 Commentaires)
(41 Commentaires)

Hi there, E-Commerce Websites Expert is here, I have considerable experience in designing and developing Website, Management systems and E-commerce sites with POS. Skills:- WordPress || WooCommerce || Shopify || Wix || Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 7 jours
(8 Commentaires)

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 Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 3 jours
(1 Évaluation)

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 wor Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 2 jours
(2 Commentaires)

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

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(0 Commentaires)

*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 s Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 7 jours
(0 Commentaires)