To change the WooCommerce order pages back to posts without using a plugin, you can modify the post type of WooCommerce orders in WordPress. This can be achieved by adding custom code to your theme’s functions.php file or creating a custom plugin. Here are the steps to do this:
- Access Your WordPress Files: You can access your WordPress files through an FTP client or a file manager provided by your hosting provider.
- Locate the Theme’s
functions.php
File: If you want to add the code to your theme, navigate to your WordPress theme’s directory, usually located atwp-content/themes/your-theme-name/
. - Edit
functions.php
: Open thefunctions.php
file for editing. You can use a code editor or a plain text editor. - Add the Following Code to
functions.php
:
/**
* Change WooCommerce order post type to 'post'.
*/
function change_woocommerce_order_post_type() {
global $wpdb;
// Define the new post type (in this case, 'post').
$new_post_type="post";
// Define the old post type (WooCommerce order post type, which is 'shop_order').
$old_post_type="shop_order";
// Update the post type in the database.
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->posts} SET post_type = %s WHERE post_type = %s",
$new_post_type,
$old_post_type
)
);
}
// Hook the function to run during the 'init' action.
add_action('init', 'change_woocommerce_order_post_type');
-
Save the File: After adding the code, save the
functions.php
file. -
Clear WordPress Cache: If you have a caching plugin installed, make sure to clear the cache.
-
Test: Now, when you go to your WooCommerce orders page, you should see that orders are displayed as posts rather than pages.
This code hooks into the WordPress init
action and updates the post type for WooCommerce orders in the database from ‘shop_order’ to ‘post’. It effectively changes the orders from being treated as pages to being treated as regular posts.
Make sure to backup your site before making any code changes, and be cautious when editing theme files or adding custom code.