0
0
Wordpressframework~10 mins

Order management in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the order ID in a WooCommerce order loop.

Wordpress
<?php
$order = wc_get_order([1]);
echo $order->get_id();
?>
Drag options to blanks, or click blank then click option'
A$order_id
B$post->ID
C1234
D$order->ID
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that is not defined like $order_id
Trying to access $order->ID directly before creating the order object
2fill in blank
medium

Complete the code to get the billing email from a WooCommerce order object.

Wordpress
<?php
$email = $order->[1]();
echo $email;
?>
Drag options to blanks, or click blank then click option'
Aget_customer_email
Bget_email_billing
Cget_billing_email
Dget_billing_phone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist like get_customer_email
Mixing the order of words in the method name
3fill in blank
hard

Fix the error in the code to update the order status to 'completed'.

Wordpress
<?php
$order = wc_get_order($order_id);
$order->[1]('completed');
$order->save();
?>
Drag options to blanks, or click blank then click option'
Aset_status
Bupdate_status
Cchange_status
Dstatus_set
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like update_status or change_status
Not calling save() after setting the status
4fill in blank
hard

Fill both blanks to create an array of order IDs for orders with status 'processing'.

Wordpress
<?php
$orders = wc_get_orders(array(
    'status' => '[1]',
    'limit' => [2]
));
$order_ids = wp_list_pluck($orders, 'ID');
?>
Drag options to blanks, or click blank then click option'
Aprocessing
Bcompleted
C10
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong status like 'completed' when filtering for processing
Using a string instead of a number for limit
5fill in blank
hard

Fill the blanks to create a dictionary of product names and quantities from an order.

Wordpress
<?php
$items = $order->get_items();
$product_quantities = array();
foreach ($items as $item) {
    $product_quantities[[1]] = [2];
}
return $product_quantities;
?>
Drag options to blanks, or click blank then click option'
A$item->get_name()
B$item->get_quantity()
C$item->get_total()
D$item->get_id()
Attempts:
3 left
💡 Hint
Common Mistakes
Using product ID instead of name as key
Using get_total() instead of get_quantity() for values