How to Add Available Lengths to Product in Shop Page

Posted by
Spread the love

A few days back, I have written a code for one of my clients shop where he needed to show available sizes for his product like the imag below .

So, that’s why I made some custom code to do this.

function display_available_sizes_on_shop_page() {
	global $product;

	if ( $product->is_type('variable') ) {
		$available_variations = $product->get_available_variations();
		$sizes = array();

		foreach ( $available_variations as $variation ) {
			$sizes[] = $variation['attributes']['attribute_pa_size'];
		}

		$sizes = array_unique($sizes);
		echo '<p class="available-sizes">Sizes: ' . implode(', ', $sizes) . '</p>';
	}
}
add_action( 'woocommerce_after_shop_loop_item', 'display_available_sizes_on_shop_page', 20 );

Where to Add this ?

You can add it to your plugin or active theme’s functions.php file. 🙂

OR,

If you find it difficult or don’t feel safe to do so, feel free to knock me for support. 🙂

About The Author

Thank you for reading this post, don't forget to subscribe!

Choose your interests. You will get future contents from the topic you select.

Bangla
Business
Career
Coding tips & tricks
Database
English
Laravel
PHP
Programming
Uncategorized
WordPress
খাদ্যাভ্যাস
চিন্তন
প্যারেন্টিং
বিজনেস
স্টোরি

Leave a Reply

Your email address will not be published. Required fields are marked *