[Plugin: Woocommerce] getting quantity of a product from a completed order
-
I have been working on a credits system for WordPress, which I installed the plugin WordPress Types. I setup my usermeta field and suddenly found myself stuck on how to add the current value of the credits onto the quantity from the latest completed order. I know where I need to put my code, but I have no idea how to extract the quantity from the order. I’ve spent all day looking through the Woocommerce API and don’t understand how to get the information that I need from it.
<?php function add_credits($order_quantity, $order_id){ global $wpdb, $current_user, $order_quantity; get_currentuserinfo(); get_order(); $current_credits = types_render_usermeta_field("credits", array("user_current" => "true", FIELD_VALUE)); if ($current_credits = "NULL"){ $current_credits = 0; } // may not have bought credits yet $newcredits = $current_credits + $order_quantity; $wpdb->update("$wpdb->usermeta", array('wpcf-credits' => $newcredits), array($currentuser->id)); } ?>
That’s the code that I have for now, but I know that I am way off and I was wondering if anyone could set me on the right course?
Thanks!
- The topic ‘[Plugin: Woocommerce] getting quantity of a product from a completed order’ is closed to new replies.