Disabling Add to Cart Button for Specific WooCommerce ProductsAdd to cart button only on one simple productWoocommerce - Add To Cart and Buy Now buttons on Product PagesWooCommerce checkout message based on specific product categoryWoocommerce custom add to cart loopWoocommerce override Product Price with custom value on cart and checkoutWoocommerce 3 - Individual Add to Cart Button for Grouped ProductsAdding Custom Meta Data from Products to Orders items in WoocommerceDisable add to cart button for specific product categories in WoocommerceChange “add to cart” button for purchased products in WoocommerceDisable ajax add to cart on first item and custom redirect it on WoocommerceAdd accept terms and conditions checkbox before Add to cart button on product page woocommerce storefront theme

Do Veracrypt encrypted volumes have any kind of brute force protection?

Nth term of Van Eck Sequence

Optimising matrix generation time

Harley Davidson clattering noise from engine, backfire and failure to start

Approach sick days in feedback meeting

Why did the Death Eaters wait to reopen the Chamber of Secrets?

Idiom for 'person who gets violent when drunk"

My parents claim they cannot pay for my college education; what are my options?

Has JSON.serialize suppressApexObjectNulls ever worked?

Opposite of "Concerto Grosso"?

Why not make one big cpu core?

What's a opened solder bridge signifies?

Would a character with eternal youth be AL-compliant?

Any gotchas in buying second-hand sanitary ware?

Can Dive Down protect a creature against Pacifism?

How effective would a full set of plate armor be against wild animals found in temperate regions (bears, snakes, wolves)?

Must a CPU have a GPU if the motherboard provides a display port (when there isn't any separate video card)?

Short story about psychologist analyzing demon

What do I need to do, tax-wise, for a sudden windfall?

Are athletes' college degrees discounted by employers and graduate school admissions?

Why is it bad to use your whole foot in rock climbing

Why can't we feel the Earth's revolution?

Commencez à vous connecter -- I don't understand the phrasing of this

Is all-caps blackletter no longer taboo?



Disabling Add to Cart Button for Specific WooCommerce Products


Add to cart button only on one simple productWoocommerce - Add To Cart and Buy Now buttons on Product PagesWooCommerce checkout message based on specific product categoryWoocommerce custom add to cart loopWoocommerce override Product Price with custom value on cart and checkoutWoocommerce 3 - Individual Add to Cart Button for Grouped ProductsAdding Custom Meta Data from Products to Orders items in WoocommerceDisable add to cart button for specific product categories in WoocommerceChange “add to cart” button for purchased products in WoocommerceDisable ajax add to cart on first item and custom redirect it on WoocommerceAdd accept terms and conditions checkbox before Add to cart button on product page woocommerce storefront theme






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm trying to disable adding to cart certain products which have the "Call to Order" checkbox ticked (see code below) on the product editor.



add_action( 'woocommerce_product_options_general_product_data', 'custom_general_product_data_custom_fields' );
/**
* Add `Call to Order` field in the Product data's General tab.
*/
function custom_general_product_data_custom_fields()
// Checkbox.
woocommerce_wp_checkbox(
array(
'id' => '_not_ready_to_sell',
'wrapper_class' => 'show_if_simple',
'label' => __( 'Call to Order', 'woocommerce' ),
'description' => __( '', 'woocommerce' )
)
);


add_action( 'woocommerce_process_product_meta', 'custom_save_general_proddata_custom_fields' );
/**
* Save the data values from the custom fields.
* @param int $post_id ID of the current product.
*/
function custom_save_general_proddata_custom_fields( $post_id )
// Checkbox.
$woocommerce_checkbox = isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_not_ready_to_sell', $woocommerce_checkbox );


add_filter( 'woocommerce_is_purchasable', 'custom_woocommerce_set_purchasable', 10, 2);
/**
* Mark "Not ready to sell" products as not purchasable.
*/
function custom_woocommerce_set_purchasable()
$not_ready_to_sell = get_post_meta( get_the_ID(), '_not_ready_to_sell' , true);

return ( 'yes' == $not_ready_to_sell ? false : true );



add_filter( 'woocommerce_product_add_to_cart_text', 'custom_product_add_to_cart_text' );
/**
* Change "Read More" button text for non-purchasable products.
*/
function custom_product_add_to_cart_text()
$not_ready_to_sell = get_post_meta( get_the_ID(), '_not_ready_to_sell', true );

if ( 'yes' === $not_ready_to_sell )
return __( 'Call to Order', 'woocommerce' );
else
return __( 'Add to Cart', 'woocommerce' );




The products that have the checkbox ticked, are in fact not purchasable, which is the desired outcome.



The problem I'm having is when I click "Add to Cart" for purchasable products (those without the checkbox ticked) on the product catalog page, I am redirected to the product page and a default WooCommerce message "Sorry, this product cannot be purchased." appears. What should be happening is that when the "Add to Cart" button is clicked, the product is automatically added to the cart.



Also from the single product page, I can add the purchasable cart without a problem.



I am not sure why this is happening this way. Any ideas?










share|improve this question






























    1















    I'm trying to disable adding to cart certain products which have the "Call to Order" checkbox ticked (see code below) on the product editor.



    add_action( 'woocommerce_product_options_general_product_data', 'custom_general_product_data_custom_fields' );
    /**
    * Add `Call to Order` field in the Product data's General tab.
    */
    function custom_general_product_data_custom_fields()
    // Checkbox.
    woocommerce_wp_checkbox(
    array(
    'id' => '_not_ready_to_sell',
    'wrapper_class' => 'show_if_simple',
    'label' => __( 'Call to Order', 'woocommerce' ),
    'description' => __( '', 'woocommerce' )
    )
    );


    add_action( 'woocommerce_process_product_meta', 'custom_save_general_proddata_custom_fields' );
    /**
    * Save the data values from the custom fields.
    * @param int $post_id ID of the current product.
    */
    function custom_save_general_proddata_custom_fields( $post_id )
    // Checkbox.
    $woocommerce_checkbox = isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no';
    update_post_meta( $post_id, '_not_ready_to_sell', $woocommerce_checkbox );


    add_filter( 'woocommerce_is_purchasable', 'custom_woocommerce_set_purchasable', 10, 2);
    /**
    * Mark "Not ready to sell" products as not purchasable.
    */
    function custom_woocommerce_set_purchasable()
    $not_ready_to_sell = get_post_meta( get_the_ID(), '_not_ready_to_sell' , true);

    return ( 'yes' == $not_ready_to_sell ? false : true );



    add_filter( 'woocommerce_product_add_to_cart_text', 'custom_product_add_to_cart_text' );
    /**
    * Change "Read More" button text for non-purchasable products.
    */
    function custom_product_add_to_cart_text()
    $not_ready_to_sell = get_post_meta( get_the_ID(), '_not_ready_to_sell', true );

    if ( 'yes' === $not_ready_to_sell )
    return __( 'Call to Order', 'woocommerce' );
    else
    return __( 'Add to Cart', 'woocommerce' );




    The products that have the checkbox ticked, are in fact not purchasable, which is the desired outcome.



    The problem I'm having is when I click "Add to Cart" for purchasable products (those without the checkbox ticked) on the product catalog page, I am redirected to the product page and a default WooCommerce message "Sorry, this product cannot be purchased." appears. What should be happening is that when the "Add to Cart" button is clicked, the product is automatically added to the cart.



    Also from the single product page, I can add the purchasable cart without a problem.



    I am not sure why this is happening this way. Any ideas?










    share|improve this question


























      1












      1








      1


      1






      I'm trying to disable adding to cart certain products which have the "Call to Order" checkbox ticked (see code below) on the product editor.



      add_action( 'woocommerce_product_options_general_product_data', 'custom_general_product_data_custom_fields' );
      /**
      * Add `Call to Order` field in the Product data's General tab.
      */
      function custom_general_product_data_custom_fields()
      // Checkbox.
      woocommerce_wp_checkbox(
      array(
      'id' => '_not_ready_to_sell',
      'wrapper_class' => 'show_if_simple',
      'label' => __( 'Call to Order', 'woocommerce' ),
      'description' => __( '', 'woocommerce' )
      )
      );


      add_action( 'woocommerce_process_product_meta', 'custom_save_general_proddata_custom_fields' );
      /**
      * Save the data values from the custom fields.
      * @param int $post_id ID of the current product.
      */
      function custom_save_general_proddata_custom_fields( $post_id )
      // Checkbox.
      $woocommerce_checkbox = isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no';
      update_post_meta( $post_id, '_not_ready_to_sell', $woocommerce_checkbox );


      add_filter( 'woocommerce_is_purchasable', 'custom_woocommerce_set_purchasable', 10, 2);
      /**
      * Mark "Not ready to sell" products as not purchasable.
      */
      function custom_woocommerce_set_purchasable()
      $not_ready_to_sell = get_post_meta( get_the_ID(), '_not_ready_to_sell' , true);

      return ( 'yes' == $not_ready_to_sell ? false : true );



      add_filter( 'woocommerce_product_add_to_cart_text', 'custom_product_add_to_cart_text' );
      /**
      * Change "Read More" button text for non-purchasable products.
      */
      function custom_product_add_to_cart_text()
      $not_ready_to_sell = get_post_meta( get_the_ID(), '_not_ready_to_sell', true );

      if ( 'yes' === $not_ready_to_sell )
      return __( 'Call to Order', 'woocommerce' );
      else
      return __( 'Add to Cart', 'woocommerce' );




      The products that have the checkbox ticked, are in fact not purchasable, which is the desired outcome.



      The problem I'm having is when I click "Add to Cart" for purchasable products (those without the checkbox ticked) on the product catalog page, I am redirected to the product page and a default WooCommerce message "Sorry, this product cannot be purchased." appears. What should be happening is that when the "Add to Cart" button is clicked, the product is automatically added to the cart.



      Also from the single product page, I can add the purchasable cart without a problem.



      I am not sure why this is happening this way. Any ideas?










      share|improve this question
















      I'm trying to disable adding to cart certain products which have the "Call to Order" checkbox ticked (see code below) on the product editor.



      add_action( 'woocommerce_product_options_general_product_data', 'custom_general_product_data_custom_fields' );
      /**
      * Add `Call to Order` field in the Product data's General tab.
      */
      function custom_general_product_data_custom_fields()
      // Checkbox.
      woocommerce_wp_checkbox(
      array(
      'id' => '_not_ready_to_sell',
      'wrapper_class' => 'show_if_simple',
      'label' => __( 'Call to Order', 'woocommerce' ),
      'description' => __( '', 'woocommerce' )
      )
      );


      add_action( 'woocommerce_process_product_meta', 'custom_save_general_proddata_custom_fields' );
      /**
      * Save the data values from the custom fields.
      * @param int $post_id ID of the current product.
      */
      function custom_save_general_proddata_custom_fields( $post_id )
      // Checkbox.
      $woocommerce_checkbox = isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no';
      update_post_meta( $post_id, '_not_ready_to_sell', $woocommerce_checkbox );


      add_filter( 'woocommerce_is_purchasable', 'custom_woocommerce_set_purchasable', 10, 2);
      /**
      * Mark "Not ready to sell" products as not purchasable.
      */
      function custom_woocommerce_set_purchasable()
      $not_ready_to_sell = get_post_meta( get_the_ID(), '_not_ready_to_sell' , true);

      return ( 'yes' == $not_ready_to_sell ? false : true );



      add_filter( 'woocommerce_product_add_to_cart_text', 'custom_product_add_to_cart_text' );
      /**
      * Change "Read More" button text for non-purchasable products.
      */
      function custom_product_add_to_cart_text()
      $not_ready_to_sell = get_post_meta( get_the_ID(), '_not_ready_to_sell', true );

      if ( 'yes' === $not_ready_to_sell )
      return __( 'Call to Order', 'woocommerce' );
      else
      return __( 'Add to Cart', 'woocommerce' );




      The products that have the checkbox ticked, are in fact not purchasable, which is the desired outcome.



      The problem I'm having is when I click "Add to Cart" for purchasable products (those without the checkbox ticked) on the product catalog page, I am redirected to the product page and a default WooCommerce message "Sorry, this product cannot be purchased." appears. What should be happening is that when the "Add to Cart" button is clicked, the product is automatically added to the cart.



      Also from the single product page, I can add the purchasable cart without a problem.



      I am not sure why this is happening this way. Any ideas?







      php wordpress woocommerce product custom-fields






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 1:47









      LoicTheAztec

      104k1576120




      104k1576120










      asked Mar 25 at 0:51









      Farrukh KarimovFarrukh Karimov

      365




      365






















          1 Answer
          1






          active

          oldest

          votes


















          1














          I have tested your code and it work without problems… I don't have the problematic behavior you describe… So something else is making trouble:



          You will need first to make a database backup… Then you should try to:



          1. Check if in your other customizations, there is something that is disabling Ajax add to cart and making that message appear. Try to comment your other customizations to find the guilty one.

          2. Try to disable all third party plugins related to Woocommerce (except Woocommerce). If the problem is gone, re-enable them one by one to find the guilty.

          The problem could come from the theme too.




          Now since Woocommerce 3 and introduced CRUD Objects, your code is a bit outdated.



          Here is revisited and enhanced code version (for Woocommerce 3+):



          // Add a custom field in the Product data's General tab (for simple products).
          add_action( 'woocommerce_product_options_general_product_data', 'add_general_product_data_custom_field' );
          function add_general_product_data_custom_field()
          woocommerce_wp_checkbox( array( // Checkbox.
          'id' => '_not_ready_to_sell',
          'label' => __( 'Call to Order', 'woocommerce' ),
          'wrapper_class' => 'show_if_simple',
          ) );


          // Save custom field value
          add_action( 'woocommerce_admin_process_product_object', 'save_general_product_data_custom_field', 10, 1 );
          function save_general_product_data_custom_field( $product )
          $product->update_meta_data( '_not_ready_to_sell', isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no' );


          // Make not purchasable, products with '_not_ready_to_sell' meta data set to "yes" (for simple products)
          add_filter( 'woocommerce_is_purchasable', 'filter_woocommerce_set_purchasable', 10, 2);
          function filter_woocommerce_set_purchasable( $purchasable, $product )
          return 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') ? false : $purchasable;



          // Change button text to "Call to Order" for simple products not purchasable.
          add_filter( 'woocommerce_product_add_to_cart_text', 'filter_product_add_to_cart_text', 10, 2 );
          function filter_product_add_to_cart_text( $button_text, $product )
          if ( 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') )
          $button_text = __( 'Call to Order', 'woocommerce' );

          return $button_text;



          Code goes on function.php file of your active child theme (or active theme). It could works.






          share|improve this answer























          • I added your code instead of mine, and it works!! I found the snippet above sridharkatakam.com/…, so maybe it's a bit outdated for WooCommerce 3.0+. Thanks for you help! Really appreciate it!

            – Farrukh Karimov
            Mar 25 at 1:57











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330032%2fdisabling-add-to-cart-button-for-specific-woocommerce-products%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I have tested your code and it work without problems… I don't have the problematic behavior you describe… So something else is making trouble:



          You will need first to make a database backup… Then you should try to:



          1. Check if in your other customizations, there is something that is disabling Ajax add to cart and making that message appear. Try to comment your other customizations to find the guilty one.

          2. Try to disable all third party plugins related to Woocommerce (except Woocommerce). If the problem is gone, re-enable them one by one to find the guilty.

          The problem could come from the theme too.




          Now since Woocommerce 3 and introduced CRUD Objects, your code is a bit outdated.



          Here is revisited and enhanced code version (for Woocommerce 3+):



          // Add a custom field in the Product data's General tab (for simple products).
          add_action( 'woocommerce_product_options_general_product_data', 'add_general_product_data_custom_field' );
          function add_general_product_data_custom_field()
          woocommerce_wp_checkbox( array( // Checkbox.
          'id' => '_not_ready_to_sell',
          'label' => __( 'Call to Order', 'woocommerce' ),
          'wrapper_class' => 'show_if_simple',
          ) );


          // Save custom field value
          add_action( 'woocommerce_admin_process_product_object', 'save_general_product_data_custom_field', 10, 1 );
          function save_general_product_data_custom_field( $product )
          $product->update_meta_data( '_not_ready_to_sell', isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no' );


          // Make not purchasable, products with '_not_ready_to_sell' meta data set to "yes" (for simple products)
          add_filter( 'woocommerce_is_purchasable', 'filter_woocommerce_set_purchasable', 10, 2);
          function filter_woocommerce_set_purchasable( $purchasable, $product )
          return 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') ? false : $purchasable;



          // Change button text to "Call to Order" for simple products not purchasable.
          add_filter( 'woocommerce_product_add_to_cart_text', 'filter_product_add_to_cart_text', 10, 2 );
          function filter_product_add_to_cart_text( $button_text, $product )
          if ( 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') )
          $button_text = __( 'Call to Order', 'woocommerce' );

          return $button_text;



          Code goes on function.php file of your active child theme (or active theme). It could works.






          share|improve this answer























          • I added your code instead of mine, and it works!! I found the snippet above sridharkatakam.com/…, so maybe it's a bit outdated for WooCommerce 3.0+. Thanks for you help! Really appreciate it!

            – Farrukh Karimov
            Mar 25 at 1:57















          1














          I have tested your code and it work without problems… I don't have the problematic behavior you describe… So something else is making trouble:



          You will need first to make a database backup… Then you should try to:



          1. Check if in your other customizations, there is something that is disabling Ajax add to cart and making that message appear. Try to comment your other customizations to find the guilty one.

          2. Try to disable all third party plugins related to Woocommerce (except Woocommerce). If the problem is gone, re-enable them one by one to find the guilty.

          The problem could come from the theme too.




          Now since Woocommerce 3 and introduced CRUD Objects, your code is a bit outdated.



          Here is revisited and enhanced code version (for Woocommerce 3+):



          // Add a custom field in the Product data's General tab (for simple products).
          add_action( 'woocommerce_product_options_general_product_data', 'add_general_product_data_custom_field' );
          function add_general_product_data_custom_field()
          woocommerce_wp_checkbox( array( // Checkbox.
          'id' => '_not_ready_to_sell',
          'label' => __( 'Call to Order', 'woocommerce' ),
          'wrapper_class' => 'show_if_simple',
          ) );


          // Save custom field value
          add_action( 'woocommerce_admin_process_product_object', 'save_general_product_data_custom_field', 10, 1 );
          function save_general_product_data_custom_field( $product )
          $product->update_meta_data( '_not_ready_to_sell', isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no' );


          // Make not purchasable, products with '_not_ready_to_sell' meta data set to "yes" (for simple products)
          add_filter( 'woocommerce_is_purchasable', 'filter_woocommerce_set_purchasable', 10, 2);
          function filter_woocommerce_set_purchasable( $purchasable, $product )
          return 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') ? false : $purchasable;



          // Change button text to "Call to Order" for simple products not purchasable.
          add_filter( 'woocommerce_product_add_to_cart_text', 'filter_product_add_to_cart_text', 10, 2 );
          function filter_product_add_to_cart_text( $button_text, $product )
          if ( 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') )
          $button_text = __( 'Call to Order', 'woocommerce' );

          return $button_text;



          Code goes on function.php file of your active child theme (or active theme). It could works.






          share|improve this answer























          • I added your code instead of mine, and it works!! I found the snippet above sridharkatakam.com/…, so maybe it's a bit outdated for WooCommerce 3.0+. Thanks for you help! Really appreciate it!

            – Farrukh Karimov
            Mar 25 at 1:57













          1












          1








          1







          I have tested your code and it work without problems… I don't have the problematic behavior you describe… So something else is making trouble:



          You will need first to make a database backup… Then you should try to:



          1. Check if in your other customizations, there is something that is disabling Ajax add to cart and making that message appear. Try to comment your other customizations to find the guilty one.

          2. Try to disable all third party plugins related to Woocommerce (except Woocommerce). If the problem is gone, re-enable them one by one to find the guilty.

          The problem could come from the theme too.




          Now since Woocommerce 3 and introduced CRUD Objects, your code is a bit outdated.



          Here is revisited and enhanced code version (for Woocommerce 3+):



          // Add a custom field in the Product data's General tab (for simple products).
          add_action( 'woocommerce_product_options_general_product_data', 'add_general_product_data_custom_field' );
          function add_general_product_data_custom_field()
          woocommerce_wp_checkbox( array( // Checkbox.
          'id' => '_not_ready_to_sell',
          'label' => __( 'Call to Order', 'woocommerce' ),
          'wrapper_class' => 'show_if_simple',
          ) );


          // Save custom field value
          add_action( 'woocommerce_admin_process_product_object', 'save_general_product_data_custom_field', 10, 1 );
          function save_general_product_data_custom_field( $product )
          $product->update_meta_data( '_not_ready_to_sell', isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no' );


          // Make not purchasable, products with '_not_ready_to_sell' meta data set to "yes" (for simple products)
          add_filter( 'woocommerce_is_purchasable', 'filter_woocommerce_set_purchasable', 10, 2);
          function filter_woocommerce_set_purchasable( $purchasable, $product )
          return 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') ? false : $purchasable;



          // Change button text to "Call to Order" for simple products not purchasable.
          add_filter( 'woocommerce_product_add_to_cart_text', 'filter_product_add_to_cart_text', 10, 2 );
          function filter_product_add_to_cart_text( $button_text, $product )
          if ( 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') )
          $button_text = __( 'Call to Order', 'woocommerce' );

          return $button_text;



          Code goes on function.php file of your active child theme (or active theme). It could works.






          share|improve this answer













          I have tested your code and it work without problems… I don't have the problematic behavior you describe… So something else is making trouble:



          You will need first to make a database backup… Then you should try to:



          1. Check if in your other customizations, there is something that is disabling Ajax add to cart and making that message appear. Try to comment your other customizations to find the guilty one.

          2. Try to disable all third party plugins related to Woocommerce (except Woocommerce). If the problem is gone, re-enable them one by one to find the guilty.

          The problem could come from the theme too.




          Now since Woocommerce 3 and introduced CRUD Objects, your code is a bit outdated.



          Here is revisited and enhanced code version (for Woocommerce 3+):



          // Add a custom field in the Product data's General tab (for simple products).
          add_action( 'woocommerce_product_options_general_product_data', 'add_general_product_data_custom_field' );
          function add_general_product_data_custom_field()
          woocommerce_wp_checkbox( array( // Checkbox.
          'id' => '_not_ready_to_sell',
          'label' => __( 'Call to Order', 'woocommerce' ),
          'wrapper_class' => 'show_if_simple',
          ) );


          // Save custom field value
          add_action( 'woocommerce_admin_process_product_object', 'save_general_product_data_custom_field', 10, 1 );
          function save_general_product_data_custom_field( $product )
          $product->update_meta_data( '_not_ready_to_sell', isset( $_POST['_not_ready_to_sell'] ) ? 'yes' : 'no' );


          // Make not purchasable, products with '_not_ready_to_sell' meta data set to "yes" (for simple products)
          add_filter( 'woocommerce_is_purchasable', 'filter_woocommerce_set_purchasable', 10, 2);
          function filter_woocommerce_set_purchasable( $purchasable, $product )
          return 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') ? false : $purchasable;



          // Change button text to "Call to Order" for simple products not purchasable.
          add_filter( 'woocommerce_product_add_to_cart_text', 'filter_product_add_to_cart_text', 10, 2 );
          function filter_product_add_to_cart_text( $button_text, $product )
          if ( 'yes' === $product->get_meta( '_not_ready_to_sell' ) && $product->is_type('simple') )
          $button_text = __( 'Call to Order', 'woocommerce' );

          return $button_text;



          Code goes on function.php file of your active child theme (or active theme). It could works.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 1:46









          LoicTheAztecLoicTheAztec

          104k1576120




          104k1576120












          • I added your code instead of mine, and it works!! I found the snippet above sridharkatakam.com/…, so maybe it's a bit outdated for WooCommerce 3.0+. Thanks for you help! Really appreciate it!

            – Farrukh Karimov
            Mar 25 at 1:57

















          • I added your code instead of mine, and it works!! I found the snippet above sridharkatakam.com/…, so maybe it's a bit outdated for WooCommerce 3.0+. Thanks for you help! Really appreciate it!

            – Farrukh Karimov
            Mar 25 at 1:57
















          I added your code instead of mine, and it works!! I found the snippet above sridharkatakam.com/…, so maybe it's a bit outdated for WooCommerce 3.0+. Thanks for you help! Really appreciate it!

          – Farrukh Karimov
          Mar 25 at 1:57





          I added your code instead of mine, and it works!! I found the snippet above sridharkatakam.com/…, so maybe it's a bit outdated for WooCommerce 3.0+. Thanks for you help! Really appreciate it!

          – Farrukh Karimov
          Mar 25 at 1:57



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330032%2fdisabling-add-to-cart-button-for-specific-woocommerce-products%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현