Ecommerce Shopify WordPress Discussion

Only display images for WooCommerce orders with a specific status

I'd like to only show images or text when a user has any WooCommerce order with status of "shipped" (this is a custom status I already have defined). My thought was to designate those items (the ones I want to show or hide) with a class and add php but I'm lost. I have tried function check_user_orders_status() { if (is_user_logged_in()) { $user_id = get_current_user_id(); $has_shipped_orders = wc_get_orders(array( 'limit' => 1, 'customer' => $user_id, 'status' => 'shipped', )); return count($has_shipped_orders) > 0; } return false; }
The following will add the order status in the body class on customer orders (order view), on order received and order pay pages. The order status will be outputted as "status-" + the current order status, like: status-processing for a "processing" order status, status-shipped for a "shipped" order status, … and so on … So you will be able to add some CSS targeting specific order status for specific elements to show or hide, like: .status-shipped .element-to-target { display:none; } The code: add_filter( 'body_class', 'add_order_status_to_body_class' ); function add_order_status_to_body_class( $classes ){ global $wp; foreach ( array('view-order', 'order-received', 'order-pay') as $endpoint ) { if ( is_wc_endpoint_url($endpoint) && isset($wp->query_vars[$endpoint]) ) { $order_id = intval($wp->query_vars[$endpoint]); // The order ID $order = wc_get_order( $order_id ); // The WC_Order object $classes[] = 'status-' . $order->get_status(); } } return $classes; } Code goes in functions.php file of your child theme (or in a plugin). Tested and works.

February 4, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.