0

I am trying to hide view more button only for those product which product have no price .this is working for out of stock product .but I want remove read more button only for product with no price .

 if (!function_exists('woocommerce_template_loop_add_to_cart')) {
        function woocommerce_template_loop_add_to_cart() {
            global $product;
            if ( ! $product->$product->price() || ! $product->is_purchasable() ) return;
            woocommerce_get_template('loop/add-to-cart.php');
        }
    }

I want use somthing like this

if( empty($product->price) )
1

Instead of eliminating the loop/add-to-cart.php template all together, why not hook into the price html Woocommerce hooks?

/*
 * Remove price HTML if stock is null
 *
 * Sources:
 * http://woocommerce.wp-a2z.org/oik_api/wc_productget_stock_quantity/
 */
add_filter( "woocommerce_get_price_html", "wphelpsanjay_remove_price_if_no_stock", 10, 2 );
add_filter( "woocommerce_variable_price_html", "wphelpsanjay_remove_price_if_no_stock", 10, 2 );

function wphelpsanjay_remove_price_if_no_stock( $price, $product ) {
    if ( null === $product->get_stock_quantity()) {
        return "";
    }
    return $price;
}
  • Tom@ i do not want remove price I want remove view more button if product price is empty – Sanjay Yadav Oct 24 '17 at 15:24
  • Tom Morton@you there ,I need your help bro – Sanjay Yadav Oct 29 '17 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.