• Resolved ventilmaskedk

    (@ventilmaskedk)


    I made a cool dropdown with prices in my shop with this code from Branahr. Thanks for that.

    Now i have an issue, because i started to have stock quantities for each product. And the dropdown displays the stock amount, which is confusing to the customer. Does anybody know how i can have this dropdown, but without it showing the amount in stock?

    Thanks in advance ??

    function display_price_in_variation_option_name( $term ) {
        $product = wc_get_product();
    	$id = $product->get_id();
        if ( empty( $term ) || empty( $id ) ) {
    		return $term;
    	}
    	if ( $product->is_type( 'variable' ) ) {
    		$product_variations = $product->get_available_variations();
    	} else {
    		return $term;
    	}
    
    	foreach($product_variations as $variation){
    		if(count($variation['attributes']) > 1){
    			return $term;
    		}
    		foreach($variation['attributes'] as $key => $slug){
    			if("attribute_" == mb_substr( $key, 0, 10 )){
    				$taxonomy = mb_substr( $key, 10 ) ;
    				$attribute = get_term_by('slug', $slug, $taxonomy);
    				if($attribute->name == $term){
    					$term .= " (" . wp_kses( wc_price($variation['display_price']), array()) . ")";
    				}
    			}
    		}
    	}
    	
        return $term;
    
    }
    add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' );

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Ron Rennick

    (@wpmuguru)

    Hi @ventilmaskedk,

    The code snippet you posted isn’t adding the amount in stock to the display.

    Thread Starter ventilmaskedk

    (@ventilmaskedk)

    Hi mate.

    I have removed the stock quantities for the products affected. When i add the stock quantities, its diplaying the stock amount on the dropdown.

    Im not sure how to add a picture here, but there is a screenshot of it here.

    DROPBOX LINK

    It displays the stock under each variant.

    Plugin Support mouli a11n

    (@mouli)

    @ventilmaskedk
    Have you tried setting the Stock display format to Never show quantity in stock?


    Link to image: https://d.pr/i/D7HVgV

    The setting is to be found under:
    WooCommerce ? Settings ? Products ? Inventory

    I hope that helps you to figure it out.
    Feel free to get back to us if you have further questions.

    • This reply was modified 4 years, 4 months ago by mouli a11n. Reason: typo

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Issue with product dropdown with price’ is closed to new replies.