• Heya guys,

    I am working on a solution to add B2B customer acvcounts to wordpress. To facilitate that, the main account should be able to view the orders of its employees (which are other wordpress users). I succeeded to make a table with the necessary orders on the my account page, but I am stuck on view-order page. I found out that if I would change _customer_user in wp_postmeta, I would be able to view the order.

    I have tried putting the following code at the beginning of view-order.php:

    global $wpdb;
    $sql=”UPDATE wp_postmeta SET meta_value = ‘9’ WHERE meta_key =4683″;
    $wpdb->query($sql);

    The problem is that it executes after all the necessary details are loaded, so I am getting an invalid order error. Of course, in a later point, I would change 9 tot get_current_user and meta_key to order_id and meta_key. So my question is where should I put this function for it to work correctly?

    Thanks.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You can put it in functions.php of your theme, or better yet, that of a child theme. You should put it inside a conditional that checks $_SERVER['REQUEST_URI'] for the proper request so that meta is not needlessly changed for unrelated requests.

    Maybe it doesn’t matter, but you might consider storing the original value in a global or transient, then restoring it in post meta after the desired information is output. The restoration part can be placed near the end of view-order.php.

Viewing 1 replies (of 1 total)
  • The topic ‘Change _customer_user’ is closed to new replies.