When price is 0 change add to cart button to “request quote” [duplicate]

大兔子大兔子 提交于 2019-12-08 11:44:45

问题


I have a product X in several sizes (added as variation products of the main product X). For small sizes the price is available and customers can shop it online. However, for large sizes of this product X, it is not shopable online. Therefore for some variations of this product X I would like to remove the add to cart button and change it to a button who goes to my "request a quote" page.

My idea was that if I set the variable product price to 0 that the add to cart button goes away and the "request a quote" button appears.

Any ideas on how to do this in woocommerce (php)?


回答1:


put this function in your function.php

add_filter('woocommerce_get_price_html', 'requestQuote', 10, 2);

function requestQuote($price, $product) {
        if ( $price == wc_price( 0.00 ) ){

                 remove_action( 'woocommerce_single_product_summary', 
      'woocommerce_template_single_add_to_cart', 30 );
                 return 'Request Quote';
        }


        else{
            return $price;}
    }



回答2:


you just need to make some condition with if function

    $price = 2000;
    $response = 'Add To Cart;
    if(size = XL)
    {
       $price = 0;
       $response = "You can Request another Size";
    }


来源:https://stackoverflow.com/questions/49408965/when-price-is-0-change-add-to-cart-button-to-request-quote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!