• Resolved aecorn

    (@aecorn)


    Hi, is this plugin still working with the newest woocommerce? It stopped working on our site.
    Also, could it be an idea to implement remove_action instead of just hiding buttons with CSS?
    Something along these lines:

    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart');
    • This topic was modified 7 years, 2 months ago by aecorn.
Viewing 15 replies - 1 through 15 (of 19 total)
  • Can’t make this plugin to work !!

    No matter what I do, the Add to cart button is still visible.

    Can’t make this plugin to work !!

    No matter what I do, the Add to cart button is still visible.

    Thread Starter aecorn

    (@aecorn)

    @pictogram
    Do you know how to add php code to your functons.php-file?
    Try adding this:

    add_action( 'woocommerce_after_shop_loop_item','aecorn_add_custom_field_into_loop',11);
    function aecorn_add_custom_field_into_loop(){
        if (is_product()) {
    		global $product;
    		$show_hide_option = get_post_meta( $product->id, 'woo_disable_add_to_cart_checkbox', 'false' );
    		if($show_hide_option == 'disable_button'){
    			remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
    			remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart');
    			return WooCommerce::instance();
    		}
    	}
    }

    This still requires this plugin to work.

    If this seems complicated check out this plugin:
    https://pagely.com/blog/2015/03/safely-add-code-snippets-to-functions-php/

    • This reply was modified 7 years, 1 month ago by aecorn.
    Thread Starter aecorn

    (@aecorn)

    This works for me, still using CSS to hide like the plugin originally uses.

    add_action( 'woocommerce_single_product_summary','aecorn_fix_hide_add_to_cart',11);
    function aecorn_fix_hide_add_to_cart(){
        if (is_product()) {
    		global $product;
    		$show_hide_option = get_post_meta( $product->get_id(), 'woo_disable_add_to_cart_checkbox', 'false' );
    		if($show_hide_option == 'disable_button'){
    			echo '<style> div.summary.entry-summary form.cart{display:none !important}<br /> div.summary.entry-summary > p.price {display:none !important}<br /></style>';
    		}
    	}
    }
    • This reply was modified 7 years, 1 month ago by aecorn.
    • This reply was modified 7 years, 1 month ago by aecorn.
    • This reply was modified 7 years, 1 month ago by aecorn.

    Hi Aecorn,
    Thanks for taking time to answer me.

    Neither of your code snippets will make this plugin work. I tried changing time, toggle Hide or show. It just doesn’t work.

    I’m using variations for my products.

    Actually the need of my client, who managed a food catering with delivery to customers, is to be able to aotamtically disabled the capacity for some product, at a certain time, to be buyable but still visible.

    I’ve been looking everywhere for this specific functionaly without success. The closest thing I found for this is this plugin and Helios Solutions WooCommerce hide price and add to cart button.

    But neither works at all !!!

    Thanks anyway

    Thread Starter aecorn

    (@aecorn)

    Hi, can you try going to a product-edit page and swap to the “text” view.
    Try pasting this at the bottom of the description:

    <style> div.summary.entry-summary form.cart{display:none !important}<br /> div.summary.entry-summary > p.price {display:none !important}</style>

    Does that do anything?
    If not, can you post a link to your site?

    • This reply was modified 7 years, 1 month ago by aecorn.

    Hi Aecorn,

    For the sake of this plugin, I did re-enabled it, re-added the snippet you provided above in function.php and added your CSS snippet. I did try switching from my custom theme to 2017.

    Nothing happens !!!!

    The website of my client is still in development but is reachable at : https://alexgauvin.com/capricesdelectables.com

    I’m actually trying to make the plugin work for one product, which is : https://alexgauvin.com/capricesdelectables.com/produit/lasagne-au-saumon/

    Thanks

    Thread Starter aecorn

    (@aecorn)

    Okey, I think this happens because your variations-plugin is creating different div-classes for your add to cart button etc.

    This CSS, should work on your site:
    <style> d.woocommerce-variation-add-to-cart { display: none; }</style>

    Try experimenting with this, add it to the bottom of your product-description, add it back into the snippet I sent you in the beginning etc. See what works for you.

    add_action( 'woocommerce_single_product_summary','aecorn_fix_hide_add_to_cart',11);
    function aecorn_fix_hide_add_to_cart(){
        if (is_product()) {
    		global $product;
    		$show_hide_option = get_post_meta( $product->get_id(), 'woo_disable_add_to_cart_checkbox', 'false' );
    		if($show_hide_option == 'disable_button'){
    			echo '<style> d.woocommerce-variation-add-to-cart { display: none; } div.summary.entry-summary form.cart{display:none !important}<br /> div.summary.entry-summary > p.price {display:none !important}</style>';
    		}
    	}
    }

    To find CSS-selectors, I usually right-click on something in the browser, choose “inspect” or something similar. Then you can find a div-tag that you can try manipulating, and test out som CSS. Learning how to do manipulate CSS, should be your second step in wordpress, after an understanding of basic HTML.

    After that, if you feel inclined, start taking a look at PHP.
    From there, javascript, including AJAX, and maybe some understanding of databases (SQL). Good luck!

    I still feel like the plugin-authors should manage to change this plugin to work with hooks and filters, disabling through action-removals, but woocommerce might not have actions for the add-to-cart and quantity separate from the price…

    • This reply was modified 7 years, 1 month ago by aecorn.
    • This reply was modified 7 years, 1 month ago by aecorn.
    • This reply was modified 7 years, 1 month ago by aecorn.

    Thanks aecorn,

    Your CSS snippet do work by adding it to single product description. I did modified it a little bit to :
    <style> div.woocommerce-variation-add-to-cart { display: none; }</style>
    to hide only the Qty field and Add to Cart button. The rest should stay visible.

    But when I add this css slector to your function, it does not work. Here is the function including what I want to be hidden :

    add_action( 'woocommerce_single_product_summary','aecorn_fix_hide_add_to_cart',11);
    function aecorn_fix_hide_add_to_cart(){
        if (is_product()) {
    		global $product;
    		$show_hide_option = get_post_meta( $product->get_id(), 'woo_disable_add_to_cart_checkbox', 'false' );
    		if($show_hide_option == 'disable_button'){
    			echo '<style> div.woocommerce-variation-add-to-cart{display:none !important}</style>';
    		}
    	}
    }
    

    It seems to me that everything is correct, even in the plugin’s settings for this product on edit page. See https://1drv.ms/i/s!Ai6-reACWWLHgaFVNPjjQolJ-oPrOg

    What am I missing ??

    Phewww ! That was suppose to be a simple plugin stuff !!!

    Thanks

    Thread Starter aecorn

    (@aecorn)

    Depending on the way you are creating the variations, the hook “woocommerce_single_product_summary” might not be triggering, or maybe the if-statement does not ring true “if (is_product())”.
    The function I wrote might not work for variations, only single products.

    Did you say you are using a plugin for the variations, or is this base Woocommerce functionality?

    For base woocommerce variations we might need to use something like
    add_action( 'woocommerce_variable_add_to_cart', 'aecorn_fix_hide_add_to_cart', 30 );
    and
    ( $product->is_type( 'variable' ) )

    To actually check this I need to set up a woocommerce store with variations to test in and that will take some time. Do you think you can work with just pasting the css into the product-descriptions?

    Putting together (without testing):

    add_action( 'woocommerce_variable_add_to_cart', 'aecorn_fix_hide_add_to_cart', 30 );
    function aecorn_fix_hide_add_to_cart(){
    global $product;
        if ( $product->is_type( 'variable' ) ){
    		$show_hide_option = get_post_meta( $product->get_id(), 'woo_disable_add_to_cart_checkbox', 'false' );
    		if($show_hide_option == 'disable_button'){
    			echo '<style>div.woocommerce-variation-add-to-cart { display: none; };</style>';
    		}
    	}
    }
    • This reply was modified 7 years, 1 month ago by aecorn.
    • This reply was modified 7 years, 1 month ago by aecorn.

    Hi aecorn,

    Are you this plugin’s dev ? Thanks for your support.

    No, I don’t use a specific WC variation plugin on this project. But I use the Rubino theme which, I think, customized a lot the user experience of WC. Maybe that’s one cause of this issue !!

    As mentionned before, my client needs a solution as user friendly as possible. So no, I can’t offer her to work with pasting code all around. That’s why I’m looking for a solution that would let her schedule some of her products to disable Add to Cart button on specified date and time.

    I did try your last piece of code and it works … almost !!
    The show/hide dropdown makes the product show or hide accordingly.
    But the expiration date/time is not working. That functionality would be my deal.

    Thanks for your support, Really appreciated

    Thread Starter aecorn

    (@aecorn)

    No, im not the developer, that seems to be @9dpi and @tranhoang
    I just posted this thread because, like you, I had a client that needed this plugin to work. I think maybe this plugin was created for single products, but the div-class might have changed in the base woocommerce plugin, so their plugin stopped working…

    I might have to dig through the plugin to look for the piece of code that triggers the expiration date, my client only needed to hide prices on single products permanently, so their needs are not the same as your client’s.

    Thread Starter aecorn

    (@aecorn)

    This plugin only contains a single php-file which does not make it very hard to search through, what Im doing is duplicating an existing function “hatcb_add_custom_field_into_single”, and changing certain things to meet your criteria. The name of the function also needs to change, otherwise you will get a “collision” between the plugin and your variation of the function.

    There is also a function named “hatcb_add_custom_field_into_loop” in the plugin, which regards the view of the product outside the “single product page”, if you need to hide the add to cart also on other pages, take a look at that.

    Could you try this variation of the function we’ve been working on? ??

    add_action( 'woocommerce_variable_add_to_cart','aecorn_fix_hide_add_to_cart',30 );
    function aecorn_fix_hide_add_to_cart(){
        global $product;
        $show_hide_option = get_post_meta( $product->get_id(), 'woo_disable_add_to_cart_checkbox', 'false' );
        $show_hide_datetime = get_post_meta( $product->get_id(), 'woo_disable_add_to_cart_date', 'false' );
        
        $st_dt = new DateTime($show_hide_datetime); 
        $set_time = $st_dt->format('Y-m-d H:i:s');
        $current_time = current_time( 'mysql' ); 
        if($show_hide_option == 'show_button'){
              
        }else if($show_hide_option == 'disable_button'){
            if($set_time>=$current_time){
            echo '<style>div.woocommerce-variation-add-to-cart { display: none; };</style>';
            }
        }
    }

    For the nerds out there: the authors of this plugin are calling the product ID in an outdated fashion. The correct way to do it is now: $product->get_id()

    Hi aecorn,

    Thanks for support and sorry for the delay to give some feedback.

    I did try your latest variation of the function but it returns with a fatal error
    Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (25 octobre 2017 15:47) at position 6 (o): The timezone could not be found in the database in /home/user/public_html/capricesdelectables.com/wp-content/themes/yolo-rubino-child/functions.php:116 Stack trace: #0 /home/user/public_html/capricesdelectables.com/wp-content/themes/yolo-rubino-child/functions.php(116): DateTime->__construct('25 octobre 2017...') #1 /home/user/public_html/capricesdelectables.com/wp-includes/class-wp-hook.php(298): aecorn_fix_hide_add_to_cart('') #2 /home/user/public_html/capricesdelectables.com/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array) #3 /home/user/public_html/capricesdelectables.com/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #4 /home/user/public_html/capricesdelectables.com/wp-content/plugins/woocommerce/includes/wc-template-functions.php(992): do_action('woocommerce_var...') #5 /home/user/public_html/capricesdelectables.com/wp-content/plugi in /home/user/public_html/capricesdelectables.com/wp-content/themes/yolo-rubino-child/functions.php on line 116

    I’m not really a PHP specialist and this issue gives me the taste of what I should learn next ?? .

    I can’t find what would be the problem here. I did look in ” hide-add-to-cart-button.php ” and the reference to $set_time = $st_dt->format('Y-m-d H:i:s'); seems identical.

    You mention about the name of the function ! Should I rename it ? In that case, can I just pick any name ?

    Thanks again for your interest in my issue. Really appreciated

    Thread Starter aecorn

    (@aecorn)

    Can you try something really lame? Go to wordpress-general settings. Set the date-time settings to Y-m-d H:i:s
    Go back to the product and set the expiration date again…
    See if that fixes the issue, we two (me and you) might be using different timeformats than the plugin’s authors on our sites…

    Im guessing that maybe they are using outdated / non-universal methods to call and parse time? Maybe…
    Im getting this, which is not the same, but is related.
    Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (23/10/2017 20:48) at position 0 (2): Unexpected character'

    The result of your $show_hide_datetime is probably “25 octobre 2017 15:47”, which Im guessing is your expiration. $st_dt->format(‘Y-m-d H:i:s’) might not work on this because the format function doesnt understand your french time-format? Maybe? Guessing again.

    • This reply was modified 7 years, 1 month ago by aecorn.
    • This reply was modified 7 years, 1 month ago by aecorn.
Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Still working?’ is closed to new replies.