Following the suggestion by @1inmillion, I put the second filter inside the first IF
statement, which works nicely.
This is the combined code:
// 1. Add text below short description
function bja_product_unavailable_text( $content ) {
$content .= '<div class="bja_product_unavailable">This product is unavailable</div>';
return $content;
}
// 2. Remove add to cart button if product is set to unavailable and add text below short description
function bja_replace_add_to_cart_button($purchasable, $product) {
$product_unavailable = get_post_meta($product->get_id(), '_product_unavailable', true);
if ($product_unavailable === 'on') {
$purchasable = false;
add_filter('woocommerce_short_description', 'bja_product_unavailable_text', 10, 2);
}
return $purchasable;
}
add_filter('woocommerce_is_purchasable', 'bja_replace_add_to_cart_button', 10, 2);
Related Posts:
- Remove span tags from WooCommerce Downloads page
- Woocommerce Price Text
- Apply class to every paragraph that holds image?
- Remove “Insert from URL” link in Media upload – WP 3.5
- static variable loop not working in WordPress
- Edit tag cloud widget number
- Set media upload attachment link to none and hide it in WP v3.5
- How to automatically apply woocommerce product title to all product images alt tags?
- How to get the original price of the product in woocommerce?
- Woocommerce auto cancel On-Hold after X days
- Check if page parent has certain template
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- WooCommerce – Customer Order History Pagination
- The values of custom fields are not available functions.php
- Why do filters/actions require an argument count?
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- Use is_product_category() properly
- My Own layout in WooCommerce pages [closed]
- Woocommerce – remove product from category
- How to use return in my custom function instead of echo
- Changing Woocommerce flat rate every nth number of items
- How do I display a user’s previous orders as a select box option on a product?
- How do you add customer capability after Woocommerce purchase?
- Handling Body class based on Template
- WooCommerce Related Products by Attribute
- Image as Sales Badge
- Add a class to the anchor tag on HTML5 gallery
- add_action shortcut?
- Two Different Links for Same Product – WooCommerce [closed]
- How to control WordPress image metadata (using Imagick)?
- How do I add custom bulk actions to multiple custom post types?
- Show prices with tax in Woocommerce Mini Cart [closed]
- Auto-update products after they were published – Woocommerce
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce related product text
- Removing “wpautop” (auto tags) only on certain pages?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Print last modified date only on posts
- WordPress Gravatar filter is removing my custom attributes
- How can I get the values of my WordPress $wpdb query in Jquery?
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Validation algorithm in checkout field
- My new button is in the wrong place
- Redirect to another page using contact form 7? [closed]
- Alter required message using comment form api
- Add item to top of menu using a filter in functions.php
- How to make modifications only to certain elements of an HTML string on the server-side?
- Filtering a function’ output for a new continued function
- Deleting Certain terms from appearing on the front end as links
- require_once() if a product in woocommerce contains a tag [closed]
- Create page template via functions.php?
- Add meta tags to a custom header
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- woocommerce specific quantities for product
- How to have different site identity logos on each page on Astra Theme [closed]
- CSS change in woo commerce Place Order Text [closed]
- WP All Import / Update stock quantity from multiple XML files
- woocommerce related product title length
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Custom query vars filters problem with pagination
- Get the name of menu item with wp_nav_menu
- How to add aria role and schema markup to custom walker container
- Must filter functions receive all arguments passed to them?
- User filter posts by year
- Modify WooCommerce used to get all orders in dashboard
- Output product category link from WP_Query
- Variation prices breakdown only for single product page
- Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- Apply function.php filter only if url not has /amp/
- Best way to use variables in multiple functions?
- Discount in the specific product title using keyword ( Woocoommerce )
- Woocommerce – if selected attribute term equals
- split 1 cart item into instock and back ordered
- Adding product permalink on admin order page throwing error
- Add Product Permalink in woocommerce admin order page
- How to override WooCommerce Order Item Meta with data from Cart?
- Woocommerce textarea format ignored
- How can i style “echo apply_filters”
- How to generate customized filtered output for the gallery
- Add missing alt tag to featured images for “storefront” theme
- How to remove title tag with this filter
- Display text of price (minus 20%) on every product page in a sentence.
- Use WP_Query Data In Cookie
- Display a list of users with avatar filterable with alphabets
- How to add custom checkout field in user details mail template
- How to get the rating value of each comment
- AJAX: WordPress filters inside $html do not work as intended
- Setting WooCommerce currency programmatically
- Assign new post author IF another user in custom field on post transition
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- posts_clauses drop ACF get_field function
- Replace the image of a product with its video in the shop page
- Automatically change insurance quantity based on cart total [closed]
- How call WordPress shortcode inside function file
- strict custom php script on specific product category [closed]
- How to pass value to add_filter wpcf7_form_tag from another function?
- Is there a hook that I can use when a fatal error occurs?