add_filter( 'woocommerce_dropdown_variation_attribute_options_html', 'variations_options_html_callback', 10, 2); function variations_options_html_callback( $html, $args ){ $args = wp_parse_args( apply_filters( 'woocommerce_dropdown_variation_attribute_options_args', $args ), array( 'options' => false, 'attribute' => false, 'product' => false, 'selected' => false, 'name' => '', 'id' => '', 'class' => '', 'show_option_none' => __( 'Choose an option', 'woocommerce' ), ) ); $options = $args['options']; $product = $args['product']; $attribute = $args['attribute']; $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute ); $id = $args['id'] ? $args['id'] : sanitize_title( $attribute ); $class = $args['class']; $show_option_none = $args['show_option_none'] ? true : false; $show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __( 'Choose an option', 'woocommerce' ); // We'll do our best to hide the placeholder, but we'll need to show something when resetting options. if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) { $attributes = $product->get_variation_attributes(); $options = $attributes[ $attribute ]; } $html = '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">'; $html .= '<option value="">' . esc_html( $show_option_none_text ) . '</option>'; if ( ! empty( $options ) ) { if ( $product && taxonomy_exists( $attribute ) ) { // Get terms if this is a taxonomy - ordered. We need the names too. $terms = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) ); foreach ( $terms as $term ) { if ( in_array( $term->slug, $options ) ) { $stock_status = get_variation_stock_status( $product, $name, $term->slug ); $html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ).$stock_status ) . '</option>'; } } } else { foreach ( $options as $option ) { // This handles < 2.4.0 bw compatibility where text attributes were not sanitized. $selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false ); $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>'; } } } $html .= '</select>'; return $html; } function get_variation_stock_status( $product, $name, $term_slug ){ foreach ( $product->get_available_variations() as $variation ){ if($variation['attributes'][$name] == $term_slug ){ $variation_obj = wc_get_product( $variation['variation_id'] ); $stock_qty = $variation_obj->get_stock_quantity(); break; } } return $stock_qty == 0 ? ' - (Niet op voorraad)' : ' - ' . $stock_qty . ' op voorraad'; }
In case of any complain or © copyright or issues please check disclaimer page for faster resolutions.
Google analytics is a free service provided by Google
Google Analytics Google analytics is a free service provided by Google that helps webmasters, siteread more...
Create a multilingual wordpress site
Translatepress plug-in The internet is truly global in nature. An internet user in the Netherlandsread more...
Every website needs hosting
SiteGround hosting Every website needs hosting. Unless you happen to operate a web hosting agency,read more...
Block malicious web traffic
Sucuri firewall The internet is full of malicious actors. There are low-level annoyances like “scriptread more...
Why should you use Cloudways?
Cloudways hosting Web hosting is an essential service for any internet-based or internet-interfaced business. Whetherread more...
Verify that Google can find your page
Google Search console Google Search Console is a free tool from Google that helps youread more...
Search engine optimization by Yoast
Yoast Plugin Search Engine Optimization (SEO) can be a very technical field. It is alsoread more...
Wat is het verschil tussen UX en UI?
UI-design en UX-design In de wereld van webdesign, maar ook in het ontwikkelen van softwareread more...
Het snelste en beste webshopplatform Woocommerce
In case of any complain or © copyright or issues please check disclaimer page forread more...
WP Rocket is the best way to boost your site
WP Rocket Plugin WP Rocket is a WordPress plugin that facilitates faster page loads andread more...
E-commerce webshop
E-commerce is a booming industry worldwide. The advent of the internet and the rapid, sustainedread more...