melvin
melvin

Reputation: 2621

Custom Button in WooCommerce add order admin page

I want to add a custom button in the page where admin can manually create new order (Admin Order page).

Admin -> Woocommerce -> order -> Add order

After i add product and when clicked edit button can i show a custom button near to Add Meta button ? I cannot find a hook to use.

add_action( 'woocommerce_after_order_itemmeta', 'editable_order_meta_general' );
function editable_order_meta_general(){
  ?>
  <button class="add_values button"><?php _e( 'Add&nbsp;Custom', 'woocommerce' ); ?></button>
  <?php
}

I have added the above code. I got the result but the button is displayed soon after i add the product. I only want the button to display when i click edit button.

This is my error I don't want button here

This is my requirement. I want button here

#UPDATE

When i added the following code, it worked. Is it the right way ? Since woocommerce button in the same field is set display:none; initially .

add_action( 'woocommerce_after_order_itemmeta', 'editable_order_meta_general' );
function editable_order_meta_general(){
  ?>
  <div class="edit" style="display: none;">
  <button class="add_values button"><?php _e( 'Add&nbsp;Custom', 'woocommerce' ); ?></button>
  </div>
  <?php
}

#Answer

As mentioned by Loiz in comment, there is no hook in WooCommerce to achieve this requirement. Have to change logic or something else.

Upvotes: 2

Views: 4838

Answers (1)

Peter HvD
Peter HvD

Reputation: 1661

The hook you're looking for is woocommerce_order_item_add_action_buttons()

I found this tutorial: https://hungred.com/how-to/woocommerce-hook-custom-button-admin-order-page/

Hope that helps

Upvotes: 1

Related Questions