<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Eliminar el botón Añadir al carrito condicionalmente - Woocommerce				            </title>
            <link>https://iguannaweb.com/community/woocommerce/eliminar-el-boton-anadir-al-carrito-condicionalmente/</link>
            <description>De momento esto es un foro de soporte donde iré poniendo cosas que pueden servir o que utilizo a lo largo de mi trabajo. Más adelante puede que deje o permita comentarios de vosotros.</description>
            <language>es</language>
            <lastBuildDate>Wed, 18 Nov 2026 02:04:26 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Eliminar el botón Añadir al carrito condicionalmente</title>
                        <link>https://iguannaweb.com/community/woocommerce/eliminar-el-boton-anadir-al-carrito-condicionalmente/#post-11</link>
                        <pubDate>Wed, 04 Jan 2023 20:00:12 +0000</pubDate>
                        <description><![CDATA[Fuente:
Si a veces has querido bloquear la compra por determinadas condiciones en woocommerce, este plugin es lo que necesitas.
&lt;?php
/*
Plugin Name: Remove &#039;Add to cart&#039; conditionally...]]></description>
                        <content:encoded><![CDATA[<p>Fuente: <a href="https://www.damiencarbery.com/2020/03/remove-add-to-cart-button-conditionally/" target="_blank" rel="noopener">https://www.damiencarbery.com/2020/03/remove-add-to-cart-button-conditionally/</a></p>
<p>Si a veces has querido bloquear la compra por determinadas condiciones en woocommerce, este plugin es lo que necesitas.</p>
<pre contenteditable="false">&lt;?php
/*
Plugin Name: Remove 'Add to cart' conditionally
Plugin URI:  https://www.damiencarbery.com/2020/03/remove-add-to-cart-button-conditionally/
Description: Conditionally remove the 'Add to cart' button in WooCommerce.
Author: Damien Carbery
Version: 0.4
WC tested up to: 5.9.1
*/


class IsPurchasableConditionalFiltering {
    // A reference to an instance of this class.
    private static $instance;
    // Store whether 'Add to cart' button should be displayed.
    private $purchasable;


    // Returns an instance of this class. 
    public static function get_instance() {
        if ( null == self::$instance ) {
            self::$instance = new IsPurchasableConditionalFiltering;
        }
        return self::$instance;
    }


    // Initialize the plugin variables.
    public function __construct() {
        $this-&gt;purchasable = array();

        $this-&gt;init();
    }


    // Set up WordPress specfic actions.
    public function init() {
        add_filter( 'woocommerce_is_purchasable', array( $this, 'is_purchasable_conditionals' ), 10, 2 );
        
        // Remove variations dropdown and 'Add to cart' button for variable products.
        add_action( 'woocommerce_before_single_product_summary', array( $this, 'before_single_product_summary' ) );
    }
    
    
    public function is_purchasable_conditionals( $whether_purchasable, $product ) {
        // Store the product ID as $product will be overwritten if $product is a variation.
        $product_id = $product-&gt;get_id();
        
        // Return cached result.
        if ( array_key_exists( $product_id, $this-&gt;purchasable ) ) {
            return $this-&gt;purchasable;
        }

        // Only do our conditional checks if WooCommerce deems the item to be purchasable.
        if ( $whether_purchasable ) {
            $result = true;  // Default to allowing purchase.
            // Aquí puedes bloquear por condiciones de precio, tienes que decomentar el bloque de código
            // Check our specific conditions - some examples.
            /* // Product over a certain price - this must be checked at variation
            // level so do this before the $product-&gt;get_type() check.
            if ( $product-&gt;get_price() &gt; 20 ) {
                $result = false;
            }*/
            
			/* // Aquí puedes poner las ids de productos a bloquear, tienes que decomentar el bloque de código
            $ids_not_purchasable = array ( 111, 140, 437, 1733, );
			if ( in_array( $product_id, $ids_not_purchasable ) ) {
                $result = false;
            }*/

            // If this is a variation then get the parent product so that categories can be checked.
            if ( 'variation' == $product-&gt;get_type() ) {
                $product = wc_get_product( $product-&gt;get_parent_id() );
                $product_id = $product-&gt;get_id();
            }
           // Aquí puedes bloquear por categoría, tienes que decomentar el bloque de código
            // Check if product in a certain categores.
            if ( has_term( array( 'hoodies', 'accessories', 'tshirts' ), 'product_cat', $product_id ) ) {
                $result = false;
            }

            $this-&gt;purchasable = $result;
        }
        else {
            // Store that this item cannot be purchased.
            $this-&gt;purchasable = false;
        }

        return $this-&gt;purchasable;
    }


    public function before_single_product_summary() {
        $product_id = get_the_ID();
        if ( array_key_exists( $product_id, $this-&gt;purchasable ) &amp;&amp; !$this-&gt;purchasable ) {
            // Remove the variation dropdowns and 'Add to cart' button for variable products.
            remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
            remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 ); 
        }
    }
}
$IsPurchasableConditionalFiltering = new IsPurchasableConditionalFiltering;</pre>
<p> </p>]]></content:encoded>
						                            <category domain="https://iguannaweb.com/community/woocommerce/">Woocommerce</category>                        <dc:creator>Francisco GP</dc:creator>
                        <guid isPermaLink="true">https://iguannaweb.com/community/woocommerce/eliminar-el-boton-anadir-al-carrito-condicionalmente/#post-11</guid>
                    </item>
							        </channel>
        </rss>
		