Hide Price and Add to Cart for specific products

This topic has 4 replies, 2 voices, and was last updated 10 months, 2 weeks ago ago by Luca Rossi

  • Avatar: Pawel
    Pawel
    Participant
    January 10, 2024 at 13:13

    Hello
    I need to hide the price and add to cart for specific products.
    I tried to use this code below but its not working I think becouse of wrong webhooks. Could you please check it and tell me if I need to correct it? Thx

    function custom_hide_price_add_cart_buttons() {
    global $product;

    // Array of product IDs for which you want to hide the price and add to cart button
    $product_ids_to_hide = [105088];

    if ( in_array( $product->get_id(), $product_ids_to_hide ) ) {
    remove_action( ‘etheme_woocommerce_template_single_add_to_cart’, ‘woocommerce_template_single_add_to_cart’, 30 );
    remove_action( ‘etheme_woocommerce_template_single_price’, ‘woocommerce_template_single_price’, 10 );
    }
    }

    // Hook for single product pages
    add_action(‘etheme_woocommerce_before_single_product’, ‘custom_hide_price_add_cart_buttons’);

    3 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    January 11, 2024 at 04:28

    Dear Pawel,

    We hope this message finds you well.

    We would like to inform you that due to our current use of the Single Product Builder for the layout design of our products, the previously mentioned hooks will not function as intended.

    As an alternative, we kindly suggest implementing the following solution:

    
    add_filter('woocommerce_get_price_html', 'n2t_woocommerce_get_price_html', 99, 2);
    function n2t_woocommerce_get_price_html($price, $product){
        $product_ids_to_hide = [105088, 596, 604];
        if (in_array($product->get_id(), $product_ids_to_hide))
            return '';
        else
            return $price;
    }
    
    add_filter('woocommerce_product_is_in_stock', 'n2t_woocommerce_product_is_in_stock', 99, 2);
    function n2t_woocommerce_product_is_in_stock($stock, $product){
        $product_ids_to_hide = [105088, 596, 604];
        if (in_array($product->get_id(), $product_ids_to_hide))
            return false;
        else
            return $stock;
    }
    

    Please ensure to replace the placeholders ‘105088, 596, 604’ with the actual IDs of your products.

    We trust this solution will be of assistance to you. Should you have any further questions or require additional support, please do not hesitate to reach out.

    Best regards,
    The 8Theme Team

    Avatar: Pawel
    Pawel
    Participant
    January 11, 2024 at 14:01

    the proce disappera but stil there is add to cart button
    https://prnt.sc/yeiKGKcNT8A2

    Avatar: Justin
    Luca Rossi
    Support staff
    January 12, 2024 at 04:57

    Hi @Pawel,

    We kindly request that you provide us with temporary wp-admin and FTP credentials to facilitate necessary support and maintenance activities.

    To grant WP-Admin access, please proceed to create a new user account with an administrator role through your WordPress Dashboard. Once the account is established, you may securely transmit the username and password to us via the Private Content section designated for this purpose.

    For FTP access, we require the following details: FTP host, FTP username, FTP password, FTP port, and FTP encryption type. If you need assistance in creating these credentials, please reach out to your hosting provider who will guide you through the process.

    We appreciate your cooperation in this matter.

    Best Regards,
    8Theme’s Team

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.