Home Forums WoodMart support forum Reordering Size attribute

Reordering Size attribute

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #596399

    i.zagorski
    Participant

    Hello. I want to reorder the Size on the front end use that for the purpose:
    add_filter(‘woocommerce_available_variation’, ‘customize_variation_size_order’, 10, 3);
    add_filter(‘woocommerce_dropdown_variation_attribute_options_args’, ‘customize_variation_size_order_args’);

    function customize_variation_size_order($args) {
    // Define the custom size order
    $custom_size_order = array(‘XXS’, ‘XS’, ‘S’, ‘S/M’, ‘M’, ‘M/L’, ‘L’, ‘L/XL’, ‘XL’, ‘XXL’, ‘3XL’, ‘4XL’);

    if ($args[‘attribute’] === ‘pa_size’) {
    $options = $args[‘options’];

    // Sort options based on the custom order
    usort($options, function($a, $b) use ($custom_size_order) {
    $pos_a = array_search($a, $custom_size_order);
    $pos_b = array_search($b, $custom_size_order);

    // If not found, place them at the end
    $pos_a = ($pos_a === false) ? count($custom_size_order) : $pos_a;
    $pos_b = ($pos_b === false) ? count($custom_size_order) : $pos_b;

    return $pos_a – $pos_b;
    });

    $args[‘options’] = $options;
    }

    return $args;
    }

    function customize_variation_size_order_args($args, $product, $variation) {
    // Define the custom size order
    $custom_size_order = array(‘XXS’, ‘XS’, ‘S’, ‘S/M’, ‘M’, ‘M/L’, ‘L’, ‘L/XL’, ‘XL’, ‘XXL’, ‘3XL’, ‘4XL’);

    if ($args[‘attribute’] === ‘pa_size’) {
    $options = $args[‘options’];

    // Sort options based on the custom order
    usort($options, function($a, $b) use ($custom_size_order) {
    $pos_a = array_search($a, $custom_size_order);
    $pos_b = array_search($b, $custom_size_order);

    // If not found, place them at the end
    $pos_a = ($pos_a === false) ? count($custom_size_order) : $pos_a;
    $pos_b = ($pos_b === false) ? count($custom_size_order) : $pos_b;

    return $pos_a – $pos_b;
    });

    $args[‘options’] = $options;
    }

    return $args;
    }
    But it gives an error 500 . As i see the error involves the woodmart_quick_shop action, which is related to the WoodMart theme . What I am doing wrong and is there any easier way to reorder the sizes

    Attachments:
    You must be logged in to view attached files.
    #596554

    Hung Pham
    Keymaster

    Hi i.zagorski,

    Thanks for reaching to us.

    Unfortunately, it requires customization to make it work, which is out of our basic support.

    Thanks for understanding our limitations. Let me know if you have any questions.

    Kind Regards

    #596692

    i.zagorski
    Participant

    Hello. I can customize it my self just tell me in which file is the size attribute ordering logic , because there is some integrated logic which i want to reorder.

    #596954

    Hung Pham
    Keymaster

    Hi i.zagorski,

    There is a default functionality for sorting attributes, here is a video of how it works https://monosnap.com/file/5KdvHl4zNGdcFVc3BnI2v7h0yFi3Bt.

    Therefore, you can delete the custom code and use the default functionality.

    Kind Regards

Viewing 4 posts - 1 through 4 (of 4 total)