• Resolved gerardval

    (@gerardval)


    Hello,

    I use this function to disable “add to cart” when my stock = zero AND when the product is no longer available with my supplier :

    function remove_addcart() {
       global $post;
    	if (is_product()) {
    	$product = wc_get_product($post->ID);
    	$dispo = $product->get_attribute( 'pa_disponibilite' );
    	if (($dispo != 1) && (($product->stock) == 0)) {
    	add_filter( 'woocommerce_is_purchasable', '__return_false');
    		}
    	}
    }
    add_action( 'wp', 'remove_addcart' );

    It seems this code doesn’t alter FiboSearch (see image)
    How can I manage it ?
    Thanks a lot !
    Gerard

    • This topic was modified 2 years, 8 months ago by gerardval.

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

Viewing 1 replies (of 1 total)
  • Hi @gerardval

    You can use this code snippet:

    add_filter( 'dgwt/wcas/suggestion_details/product/html', function( $html, $productID ) {
    
      $product = wc_get_product( $productID );
    	
    	$stock_status  = $product->get_stock_status();
    	$disponibilite = $product->get_attribute( 'pa_disponibilite' );
    
    	if ( $disponibilite != 1 && 'instock' != $stock_status ) {
    		$html = preg_replace( '#<div class="dgwt-wcas-pd-addtc js-dgwt-wcas-pd-addtc">(.+?)</form>#s', '<div>', $html ); // Remove "Add to cart" button
    	}
    	
      return $html;
    
    }, 10, 2 );

    You have to paste the following code samples into functions.php in your child theme or use the Code Snippets plugin.

    Regards,
    Kris

Viewing 1 replies (of 1 total)
  • The topic ‘Remove “add to cart” button if 2 conditions met’ is closed to new replies.