0
0
Wordpressframework~30 mins

Order management in Wordpress - Mini Project: Build & Apply

Choose your learning style9 modes available
Order management
📖 Scenario: You are building a simple WordPress plugin to manage customer orders on a website. The plugin will store orders, set a status filter, display filtered orders, and finalize the order list display.
🎯 Goal: Create a WordPress plugin that stores a list of orders, filters them by status, loops through the filtered orders to display them, and completes the display with a summary message.
📋 What You'll Learn
Create an array called $orders with 3 orders, each order is an associative array with keys 'id', 'product', and 'status'
Create a variable called $filter_status and set it to the string 'completed'
Use array_filter with a callback function to create a new array $filtered_orders containing only orders with 'status' equal to $filter_status
Use a foreach loop to iterate over $filtered_orders and echo each order's 'id' and 'product' inside a paragraph tag
After the loop, echo a final paragraph with the text 'All completed orders are shown.'
💡 Why This Matters
🌍 Real World
Managing and displaying customer orders on a WordPress website helps store owners track order statuses and show relevant information to customers or admins.
💼 Career
Understanding how to manipulate arrays, filter data, and display dynamic content is essential for WordPress plugin development and backend PHP programming.
Progress0 / 4 steps
1
Create the orders array
Create an array called $orders with exactly these three orders: ['id' => 101, 'product' => 'T-shirt', 'status' => 'completed'], ['id' => 102, 'product' => 'Jeans', 'status' => 'pending'], and ['id' => 103, 'product' => 'Hat', 'status' => 'completed'].
Wordpress
Need a hint?

Use a PHP array with three associative arrays inside, each with keys 'id', 'product', and 'status'.

2
Set the filter status
Create a variable called $filter_status and set it to the string 'completed'.
Wordpress
Need a hint?

Just assign the string 'completed' to the variable $filter_status.

3
Filter orders by status
Use array_filter with a callback function to create a new array called $filtered_orders that contains only orders from $orders where the 'status' equals $filter_status.
Wordpress
Need a hint?

Use array_filter with an anonymous function that checks if $order['status'] equals $filter_status.

4
Display filtered orders and final message
Use a foreach loop to iterate over $filtered_orders and echo each order's 'id' and 'product' inside a paragraph tag. After the loop, echo a paragraph with the text 'All completed orders are shown.'.
Wordpress
Need a hint?

Use a foreach loop to echo each order's id and product inside <p> tags, then echo the final message in another <p> tag.