• Resolved lxjffrs

    (@lxjffrs)


    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)
  • Plugin Support Fauzan Azizie

    (@fauzanade)

    Hi @lxjffrs,

    We’ve tried to explore this feature a few years ago, however, we still couldn’t get it perfect yet. I’ve tried your snippet but it has a few limitations:

    1. Must use fixed wholesale price
    2. It’ll fetch the wholesale price as set in the product data. So it’ll ignore the tax calculation.
    3. When recalculating, it’ll use the standard tax rate. If the store has a different tax rate for each wholesale role it won’t be applied.

    Our tax calculation for the wholesale customer is quite complex, so unfortunately I can’t give an immediate hotfix for this. I’ll submit this as a feature request for the development team to investigate further.

    But I’m afraid I couldn’t give you the ETA upon completion. Kindly be patient and we’ll definitely keep you in the loop when the update is released.

    Cheers,

    Thread Starter lxjffrs

    (@lxjffrs)

    @fauzanade

    Thanks for this, I’ve just tested it and you’re right the tax calculations are ignored. However if you click my new “Calculate Wholesale Prices” button and then click the standard WooCommerce “Recalculate” button, it applies the tax calculations correctly from what I can see.

    I’m not using bulk discounts on my store so that’s not a problem for me, although I understand the solution would need to work across all use cases for it to be a good solution to include in the plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Editing Prices in backend’ is closed to new replies.