0

I am using "For specific products on WooCommerce orders with completed status, perform an action" answer to one of my previous questions.

Now I want to show some specific content if the user bought a product from a list, and the order for that product is completed. If he didn't, the user will see another content on that page. The content will be in a section from that custom page.

Any help is appreciated.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Beusebiu
  • 1,433
  • 4
  • 23
  • 68

1 Answers1

0

So the action that you need to perform is to add some custom user meta data when the conditions are met, like:

add_action('woocommerce_order_status_completed', 'action_on_order_status_completed', 10, 2 );
function action_on_order_status_completed( $order_id, $order ){
    // Here below your product list
    $products_ids = array('11', '12', '13', '14', '15', '16');
    $found = false;

    // Loop through order items
    foreach ( $order->get_items() as $item ) {
        if ( in_array($item->product_id(), $products_ids) ) {
            $found = true;
            break;
        }
    }

    if ( $found ) {
        $user_id = $order->get_customer_id(); // Get the user ID
        // Add custom user meta data
        update_user_meta( $user_id, 'show_specific_content', '1' );
    }
}

Now you can use the following to show some specific content:

if( get_user_meta( get_current_user_id(), 'show_specific_content', true ) ) {
    // Display your custom content here
} else {
    // Display something else here
}
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399