Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #855783

    Hello good day!
    Since the end of the web I have not been able to solve this. I would like to “please” help me solve it

    It turns out that items with zero price or out of stock still showing the buy button. although they are not available and have a zero price. as you can see in this screenshot:
    https://s26.postimg.org/fl8i1g4yx/noprice.jpg

    Even the product page shows the buy button. even if they are out of stock and have a zero price. as you can see in this screenshot:
    https://s26.postimg.org/4zt836o15/noprice2.jpg

    and the result when clicking is an error in Amazon when redirecting. as you can see in this screenshot.
    https://s26.postimg.org/ujvi9m9ex/noprice3.jpg

    Is there any way for that button to disappear from products with zero price? or any other idea?

    I already tried with all this and it did not work, now I return it and I wish that we can find a solution.
    https://gist.github.com/mikejolley/1751128
    https://wisdmlabs.com/blog/the-right-way-to-hide-add-to-cart-button-in-woocommerce/
    https://kriesi.at/support/topic/add-to-cart-button-showing-when-items-not-in-stock-after-woocommerce-update/
    https://kriesi.at/support/topic/hide-out-of-stock-products-in-woocommerce/

    Thanks

    • This topic was modified 6 years, 6 months ago by Astrobiologic.
    #856303

    Hey Ganubis,

    Thank you for using Enfold.

    Did you install a third party plugin to redirect the add to cart item to amazon?

    Best regards,
    Ismael

    #861679

    Hi, I’m having a similar issue to Ganubis. The add to cart button is shown even products are out of stock. When I change the theme to TwentySeventeen, the cart button is greyed out for products that are unavailable – which is correct – but when Enfold is activated is doesn’t get greyed out/hidden.

    Ideally, I’d like to remove the add to cart and quantity selector when products are out of stock or zero priced.

    Enfold team – please can you help modify this function/filter to work with Enfold:

    function remove_add_to_cart_on_0 ( $purchasable, $product ){
            if( $product->get_price() == 0 )
                $purchasable = false;
            return $purchasable;
        }
        add_filter( 'woocommerce_is_purchasable', 'remove_add_to_cart_on_0', 10, 2 );

    Many thanks
    Duncan

    #861838

    Hi Duncan,

    This code should work, have you tried it?
    Or try like this

    
    function remove_add_to_cart_on_0 ( $purchasable, $product ) {
            if( $product->get_price() == 0 || '' !== $product->get_price() ) { 
               return false;
            }
         return $purchasable;
    }
    
    add_filter( 'woocommerce_is_purchasable', 'remove_add_to_cart_on_0', 10, 2 );
    

    Best regards,
    Victoria

    #861852

    Hi Victoria, thanks for the quick reply.

    Yes, the code does work in that clicking the ‘Add to Cart’ button opens a pop-up window saying “this product is unavailable, please choose a different combination” but I’m trying to get it to remove the Add to Cart button completely when the product has a price of zero.

    Any tips on how I can add a filter in the functions to remove the Cart button and quantity selector, please?

    Many thanks
    Duncan

    #862327

    Hi,

    Please replace the filter with the following code.

    add_action( 'init', 'after_setup_theme_product_button', 100 );
    function after_setup_theme_product_button() {
    	remove_action( 'woocommerce_after_shop_loop_item', 'avia_add_cart_button', 16);
    	add_action( 'woocommerce_after_shop_loop_item', 'avia_add_cart_button_mod', 16);
    }
    
    function avia_add_cart_button_mod()
    {
    	global $product, $avia_config;
    
    	if( $product->get_price() == 0 ) return;
    
    	var_dump($product->get_price());
    
    	if ($product->get_type() == 'bundle' ){
    		$product = new WC_Product_Bundle($product->get_id());
    	}
    
    	$extraClass  = "";
    
    	ob_start();
    	woocommerce_template_loop_add_to_cart();
    	$output = ob_get_clean();
    
    	if(!empty($output))
    	{
    		$pos = strpos($output, ">");
    
    		if ($pos !== false) {
    		    $output = substr_replace($output,"><span ".av_icon_string('cart')."></span> ", $pos , strlen(1));
    		}
    	}
    
    	if($product->get_type() == 'variable' && empty($output))
    	{
    		$output = '<a class="add_to_cart_button button product_type_variable" href="'.get_permalink($product->get_id()).'"><span '.av_icon_string("details").'></span> '.__("Select options","avia_framework").'</a>';
    	}
    
    	if(in_array($product->get_type(), array('subscription', 'simple', 'bundle')))
    	{
    		$output .= '<a class="button show_details_button" href="'.get_permalink($product->get_id()).'"><span '.av_icon_string("details").'></span>  '.__("Show Details","avia_framework").'</a>';
    	}
    	else
    	{
    		$extraClass  = "single_button";
    	}
    
    	if(empty($extraClass)) $output .= " <span class='button-mini-delimiter'></span>";
    
    	if($output && !post_password_required() && '' == avia_get_option('product_layout',''))
    	{
    		echo "<div class='avia_cart_buttons $extraClass'>$output</div>";
    	}
    }

    Best regards,
    Ismael

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.