• Hi everybody,

    I try to hide add to cart button if 2 conditions (stock, and brand availability) are true whith this code. All is working, except on archive page. Why ?

    function remove_addcart() {
       $product = get_product();
    	$dispo = $product->get_attribute( 'pa_disponibilite' );
       if (($dispo > 1) && (($product->stock) == 0)) {
           remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
           remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
           remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
           remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
           remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
           remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
       }
    }
    add_action( 'wp', 'remove_addcart' );

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello @gerardval,

    To customize the “add to cart buttons” on the archive page you can customize the theme with the WooCommerce template on OceanWP theme. The solution to achieve it is customization. To do this, first, you need to use the child theme. You can copy the meta file from the partials folder in the child theme following the same path and then do necessary changes.

    For more information about that, please follow the steps below:

    By using FTP or cPanel access (if didn’t use the localhost), Go to this directory:
    wp-content\themes\oceanwp\partials
    Find your template which you want to customize and copy that template file(in your case, for example, you need to change the date on the blog pages, so you need to use the blog template(s): https://i.postimg.cc/brv9gn9s/image.png).

    Then head over to the same path on the child theme. There isn’t an entry folder as a default on your child theme, so you need to create a new one(one time).

    Example: If you want to change the HTML tags structure in the single blog posts featured image for standard post format, all you need in this step is:

    1- Head over to your WP root > wp-content > themes > oceanwp > partials> single > media path.
    2- Then, find the “blog-single.php” file and copy this file.
    3- After that, back to the themes folder (wp root > wp-content > themes) and go to oceanwp-child-theme-master folder.
    4- Create a new folder into the child theme with the “partials” name.
    5- Go to the /partials/ folder and create a new folder with the “single” name.
    6- Go to the /single/ folder and create a new folder with the “media” name.
    7- Go to the /media/ folder and paste the “blog-single.php” file here.

    * Please check this screenshot: https://i.postimg.cc/sxjYTWyt/image.png.

    Note: It’s working with the /woocommerce/ folder or root of the theme files.

    I hope that helps,
    Best Regards

    Thread Starter gerardval

    (@gerardval)

    No, I just need to know how to remove the “add to cart” button on archive pages.
    I already use a child theme.
    In functions.php, this snippet doesn’t work :
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

    I think I have to use another “taxonomy” than “woocommerce_after_shop_loop_item”, but I can’t find it.

    Thanks for helping.

    Gérard

    Hello @gerardval,

    Thanks for reaching out and letting us know.

    We did see this happening on our end, so we’ll share this with our team for investigation and fix for the next updates. For a temporary solution, you can use CSS custom code to hide the “add to cart” button on the archive page:

    .post-type-archive-product ul.products li.product .button {
        display: none;
    }

    For more information about the CSS/JS code on the customizer, please read this link:
    https://docs.oceanwp.org/article/354-add-custom-css-and-js-to-your-website

    Best Regards

    Thread Starter gerardval

    (@gerardval)

    I tried also this way, working everywhere except on archive, search and category page :

    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' );
    • This reply was modified 1 year, 9 months ago by gerardval.

    Hello @gerardval,

    Thank you for the update. I’ve updated your report to our developer team.
    I appreciate your patience until the issues are resolved.

    Best Regards

    Thread Starter gerardval

    (@gerardval)

    Hi,

    some news ?

    Hello @gerardval,

    Unfortunately, we don’t have ETA for this. However, you can follow the changelog here: https://docs.oceanwp.org/article/653-oceanwp-theme-changelog for future updates.

    Best Regards

    Thread Starter gerardval

    (@gerardval)

    Is it a way to get around this problem ? Another method ?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Remove add to cart on archive page’ is closed to new replies.