Title: Custom button admin order items
Last modified: September 1, 2022

---

# Custom button admin order items

 *  Resolved [ollkar](https://wordpress.org/support/users/ollkar/)
 * (@ollkar)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/custom-button-admin-order-items/)
 * Hi!
 * Currently trying to implement a custom button on my clients website. Im trying
   to add a button on all items in admin order page. I want the button to clear 
   the stock for that specific item.
    Have some code that somewhat works but it 
   return wrong product id. How do i make sure that i get the right product id before
   updating the stock value?
 * Current code:
 *     ```
       add_action( 'woocommerce_after_order_itemmeta', 'action_woocommerce_order_item_add_button', 10, 2);
   
       function action_woocommerce_order_item_add_button($item_id, $item)
       {
         $product = $item->get_product();
           $id = $item->get_product_id();
   
               echo '<button type="button" onclick="document.post.submit();" class="button generate-items" style="background: red; color: white;">' . __( 'Töm lagersaldo', 'hungred' ) . 
                   '<input type="hidden" value="'.$id.'" name="renew_order_single_product" /></button>';
   
       }
   
       add_action('save_post', 'renew_save_again', 10, 3);
       function renew_save_again($post_id, $post, $update){
           $slug = 'shop_order';
           if(is_admin()){
                   // If this isn't a 'woocommercer order' post, don't update it.
                   if ( $slug != $post->post_type ) {
                           return;
                   }
   
                   if(isset($_POST['renew_order_single_product']) && $_POST['renew_order_single_product']){
   
                       //removes stock for specified product
                       global $woocommerce;
                       $quantity = 0;
                       $product_id = $_POST['renew_order_single_product'];
                       $woocmmerce_instance = new WC_Product($product_id);
                       $new_quantity=wc_update_product_stock( $woocmmerce_instance, $quantity);
   
                }
           }
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [Niels Lange](https://wordpress.org/support/users/nielslange/)
 * (@nielslange)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/custom-button-admin-order-items/#post-15969896)
 * Hello [@ollkar](https://wordpress.org/support/users/ollkar/),
 * This is a fairly complex development topic. I’m going to leave it open for a 
   bit to see if anyone is able to chime in to help you out.
 * I can also recommend [the WooCommerce Developer Resources Portal](https://developer.woocommerce.com/)
   for resources on developing for WooCommerce.
 * You can also visit the [WooCommerce Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
   or the `#developers` channel of the [WooCommerce Community Slack](https://woocommerce.com/community-slack/).
   We’re lucky to have a great community of open-source developers for WooCommerce,
   and many of our developers hang out there, as well.

Viewing 1 replies (of 1 total)

The topic ‘Custom button admin order items’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [admin](https://wordpress.org/support/topic-tag/admin/)
 * [order](https://wordpress.org/support/topic-tag/order/)

 * 1 reply
 * 2 participants
 * Last reply from: [Niels Lange](https://wordpress.org/support/users/nielslange/)
 * Last activity: [3 years, 9 months ago](https://wordpress.org/support/topic/custom-button-admin-order-items/#post-15969896)
 * Status: resolved