Editing Prices in backend
-
Hi I have been trying to work out how to edit the prices in the backend for one of my customer’s sites. I found this thread – https://www.ads-software.com/support/topic/wholesale-prices-in-backend-editing-orders/ which gives a solution, with the exception of being able to find the user role. I have modified it slightly so that it will now find the correct user role and apply the correct prices upon saving.
Is there any reason why this cannot be included in the core plugin?
function action_aplicar_mayoristas($order) { echo '<button type="button" onclick="document.post.submit();" class="button button-primary generate-items">Recalculate Wholesale Prices</button>'; echo '<input type="hidden" value="1" name="aplicar_mayoristas" />'; } add_action('save_post', 'aplicar_mayoristas', 10, 3); function aplicar_mayoristas($post_id, $post, $update) { $slug = 'shop_order'; if (is_admin()) { if ($slug != $post->post_type) { return; } if (isset($_POST['aplicar_mayoristas']) && $_POST['aplicar_mayoristas']) { $roleKey = glue_studio_get_user_role(); $order = wc_get_order($post_id); foreach ($order->get_items() as $item_id => $item) { if (!wc_get_order_item_meta($item->get_id(), '_wwp_wholesale_priced', true)) { $wholesalePrice = get_post_meta($item->get_product_id(), $roleKey . '_wholesale_price', true); $item->set_subtotal($wholesalePrice * $item->get_quantity()); $item->set_total($wholesalePrice * $item->get_quantity()); $item->save(); } } } } } function glue_studio_get_user_role() { global $post; $order = wc_get_order($post->ID); $customer_id = $order->get_customer_id(); $role = get_userdata($customer_id)->roles[0]; return $role; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Editing Prices in backend’ is closed to new replies.