Home › Forums › WoodMart support forum › Reordering Size attribute
Reordering Size attribute
- This topic has 3 replies, 2 voices, and was last updated 3 months ago by Hung Pham.
-
AuthorPosts
-
September 10, 2024 at 12:27 pm #596399
i.zagorskiParticipantHello. 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 sizesAttachments:
You must be logged in to view attached files.September 11, 2024 at 5:41 am #596554
Hung PhamKeymasterHi 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
September 11, 2024 at 12:09 pm #596692
i.zagorskiParticipantHello. 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.
September 12, 2024 at 12:00 pm #596954
Hung PhamKeymasterHi 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
-
AuthorPosts
Tagged: size attribute
- You must be logged in to create new topics. Login / Register