Tagged: 

Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #738620

    How do I hide the price of a sold item, and have it displayed as sold throughout the site.

    Right now, it only lists as sold when you click on the item, not on the main page for the Shop.

    This is what I have in my Enfold Child functions.php:

    }

    add_filter( “woocommerce_variable_sale_price_html”, “theanand_remove_prices”, 10, 2 );
    add_filter( “woocommerce_variable_price_html”, “theanand_remove_prices”, 10, 2 );
    add_filter( “woocommerce_get_price_html”, “theanand_remove_prices”, 10, 2 );

    function theanand_remove_prices( $price, $product ) {
    if ( ! $product->is_in_stock()) {
    $price = “”;
    }
    return $price;
    }

    #740239

    Hey!

    Please add following code to Functions.php file in Appearance > Editor

    add_action( 'woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25 );
    //create our function
    function wcs_stock_text_shop_page() {
        //returns an array with 2 items availability and class for CSS
        global $product;
        $availability = $product->get_availability();
        //check if availability in the array = string 'Out of Stock'
        //if so display on page.//if you want to display the 'in stock' messages as well just leave out this, == 'Out of stock'
        if ( $availability['availability'] == 'Out of stock') {
            echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] );
        }
     
    }

    Best regards,
    Yigit

    #740347

    Thanks Yigt, I really appreciate your help.

    When I add your code to functions.php, I run into this error:

    Parse error: syntax error, unexpected ‘&’ in /lareventeart.com/wp-content/themes/enfold-child/functions.php on line 24

    #740691

    Hi,

    Please copy the code from our forum. It does work fine on my end. If that too does not help, please post FTP and WP admin logins here privately.

    Best regards,
    Yigit

    #740824

    It worked this time – thanks.

    The only problem is that the price appears when item is “Out of stock”- on catalogue view and product view.

    And the change only appears in English. I also have French (as the primary language) through WPML.

    It would be nice to include this change as well:

    add_filter( ‘woocommerce_get_availability’, ‘custom_get_availability’, 1, 2);
    function custom_get_availability( $availability, $_product ) {
    //change text “In Stock’ to ‘Available’
    if ( $_product->is_in_stock() ) $availability[‘availability’] = __(‘Available’, ‘woocommerce’);

    //change text “Out of Stock’ to ‘SOLD OUT’
    if ( !$_product->is_in_stock() ) $availability[‘availability’] = __(‘Sold’, ‘woocommerce’);
    return $availability;
    }

    #740903

    Hey!

    Thanks a lot for the suggestion!
    We will do ask Kriesi, although it is something that as seems, it is better to be as an extra function.
    Let us know if we can do anything else to assist you further.

    Thanks a lot

    Best regards,
    Basilis

    #740906

    Hi Basilis,

    Is there any way to display sold on the French side as well?

    And to remove the price when sold?

    Thanks!

    #743118

    Hi,

    Do you want to translate the “Sold” text to french? If you do, you can use the following plugin.

    // https://wordpress.org/plugins/say-what/

    Please provide a link to a product without stock on the French version.

    Best regards,
    Ismael

    #743364

    Thanks Ismael, I already modified the WMPL String Translation so I don’t think I need this plugin now.

    The remaining issue is the “Out of Stock” message only appears on the English catalog page: https://www.lareventeart.com/en/

    And the price is still listed when sold. I would like that to be removed in the event of a sale.

    The out of stock message does not appear at all on the French catalog page: https://www.lareventeart.com/

    Same issue with the price showing.

    #743767

    Hey!

    Did you translate these products? Did you set the Stock status after the “duplication” or “translation” process? Please post the login details here and we’ll check the settings.

    Cheers!
    Ismael

    #743916

    Yes, all products are translated and some are listed as sold (example: Dil Hildebrand, painting).

    I appreciate you taking a look!

    #744583

    Hi!

    Thank you for the info. We modified the code in the functions.php file. Please remove browser cache before checking the page.

    add_action( 'woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25 );
    function wcs_stock_text_shop_page() {
        global $product;
        $availability = $product->get_availability();
        if (!empty($availability['availability'])) {
            echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] );
        }
    }

    Regards,
    Ismael

    #744823

    Is there a way to hide price when the product is sold?

    When I remove the price manually, it does not show as a sold item..

    Thanks for your help!

    #744824

    And this little tweak does not work anymore, maybe there is a conflict?

    }

    add_filter( ‘woocommerce_get_availability’, ‘custom_get_availability’, 1, 2);
    function custom_get_availability( $availability, $_product ) {
    //change text “In Stock’ to ‘Available’
    if ( $_product->is_in_stock() ) $availability[‘availability’] = __(‘Available’, ‘woocommerce’);

    //change text “Out of Stock’ to ‘Sold’
    if ( !$_product->is_in_stock() ) $availability[‘availability’] = __(‘Sold’, ‘woocommerce’);
    return $availability;
    }

    #745258

    Hi!

    The “out of stock” and “vendu” text are displaying when I checked both languages.

    // https://www.lareventeart.com/en/
    // https://www.lareventeart.com/

    If you want to remove the price on “out of stock” products, please add this in the Quick CSS field.

    .outofstock .price {
        display: none !important;
    }

    Cheers!
    Ismael

    #745442

    I hoping to change the text ‘Out Of Stock’ to ‘Sold’.

    It’s artwork, so out of stock makes it sound like a mass produced product.

    Everything else worked like a charm!

    #745705

    Hi!

    Thank you for the update.

    We modified the filters a bit. Please remove browser cache before checking the page.

    Best regards,
    Ismael

    #745766

    Awesome, thanks so much Ismael – you’re the best!

    #746099

    Hi!

    No problem. Let us know if you need anything else. :)

    Regards,
    Ismael

Viewing 19 posts - 1 through 19 (of 19 total)
  • The topic ‘Woocommerce Hide price, mark sold throughout website’ is closed to new replies.