Home Forums WoodMart support forum delete "add to cart" for products with zero or null (empty price)

delete "add to cart" for products with zero or null (empty price)

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

    giannisth
    Participant

    hello, i am struggling to find an appropriate code to eliminate “add to cart” button for products with zero or empty price.
    i have found this but there seems to be a proplem on code
    `function remove_add_to_cart_option( $purchasable, $product ){
    if( $product->get_price() == 0 )
    $purchasable = false;
    return $purchasable;
    }
    add_filter( ‘woocommerce_is_purchasable’, ‘remove_add_to_cart_option’, 10, 2 );
    thanks a lot

    #245430

    giannisth
    Participant

    extra, if i can also add an appropriate code to eliminate “add to cart” button for products which are applied to specific attribute?
    please help!

    #245439

    giannisth
    Participant

    for attribute Nova Luce i found this code `add_filter( ‘woocommerce_variation_is_purchasable’, ‘conditional_variation_is_purchasable’, 20, 2 );
    function conditional_variation_is_purchasable( $purchasable, $product ) {

    ## —- Your settings —- ##

    $taxonomy = ‘pa_εταιρία’;
    $term_name = ‘Nova Luce’;

    ## —- The active code —- ##

    $found = false;

    // Loop through all product attributes in the variation
    foreach ( $product->get_variation_attributes() as $variation_attribute => $term_slug ){
    $attribute_taxonomy = str_replace(‘attribute_’, ”, $variation_attribute); // The taxonomy
    $term = get_term_by( ‘slug’, $term_slug, $taxonomy ); // The WP_Term object
    // Searching for attribute ‘pa_εταιρία’ with value ‘Nova Luce’
    if($attribute_taxonomy == $taxonomy && $term->name == $term_name ){
    $found = true;
    break;
    }
    }

    if( $found )
    $purchasable = false;

    return $purchasable;
    }`
    but it does not seem to work

    #245476

    Hello,

    Please remove the code and leave the price field empty. The Add to cart button would disappear.

    Best Regards

    #245493

    giannisth
    Participant

    than you for your responce!
    i had already deleted the code.
    if i can also add an appropriate code to eliminate “add to cart” button for products which are applied only to specific attribute?
    please help!

    #245574

    Hello,

    Unfortunately, our theme does not have any options. Our support scope does not cover Woocommerce customization.
    We have not met or tested a plugin.

    Best Regards

Viewing 6 posts - 1 through 6 (of 6 total)