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
- How to make a image-size selected by default in Media upload – WP v3.5
- static variable loop not working in WordPress
- adding a filter to a shortcode?
- 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?
- Change the footer text on the login page
- add_filter to post-gallery and remove all ‘s?
- Rewriting search and pagination base
- Woocommerce auto cancel On-Hold after X days
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Change comments form title on a page by page basis
- Remove class that has been added by parent theme
- WooCommerce – Customer Order History Pagination
- The values of custom fields are not available functions.php
- How do I know what variables are passed in a filter/action and what their meaning is?
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- Woocommerce filter cart and category specific quantity [closed]
- Use is_product_category() properly
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- Changing Woocommerce flat rate every nth number of items
- Limiting woocommerce line_total decimal length
- Run a filter when a walker runs
- How do I display a user’s previous orders as a select box option on a product?
- Handling Body class based on Template
- Get_avatar filter?
- How can I remove a function that has been added to wordpress with add_filter?
- Two Different Links for Same Product – WooCommerce [closed]
- 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
- Woocommerce related product text
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Unique icons next to each WordPress menu item
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Redirect to another page using contact form 7? [closed]
- 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?
- require_once() if a product in woocommerce contains a tag [closed]
- Warning: in_array() null given in PHP function
- Add meta tags to a custom header
- Remove item in Checkout
- 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
- 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
- How do i wrap woocomerce attribute in list?
- Removing files programmatically
- Must filter functions receive all arguments passed to them?
- Woocommerce order status payment
- 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
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- Apply function.php filter only if url not has /amp/
- php code for outputting a custom page in my account
- Hide specific shipping methode depending on day and time of day
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- Adding custom field to product category and show it to shop/category shop page
- Change lost password url to a mailto URL in WordPress
- Best way to use variables in multiple functions?
- Discount in the specific product title using keyword ( Woocoommerce )
- Including user data in “new user notification email”
- Adding product permalink on admin order page throwing error
- Reload page with a different shortcode when a user selects from a dropdown
- How to override WooCommerce Order Item Meta with data from Cart?
- WordPress Ajax filter: Create two loops for different output styles?
- Woocommerce textarea format ignored
- How to auto-generate random numbers in username?
- Remove generated category and tag class names from woocommerce product & blog listings markup
- WP_Query To Display Product Of Brand On Taxonomy Page
- Woocommerce Add custom “Add to cart button” in single page with tags
- How can i style “echo apply_filters”
- Get Billing Email from WooCommece Checkout and Pass to Fullstory JS
- Add missing alt tag to featured images for “storefront” theme
- How to remove title tag with this filter
- str_replace not preserving whitespace
- Use WP_Query Data In Cookie
- Limit Taxonomy Parents
- Display a post based on its metabox selection
- 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
- How to add margin underneath woocommerce total price amount -> productpages
- Setting WooCommerce currency programmatically
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- 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]
- Replace the image of a product with its video in the shop page
- How to add different menu items on different menus?
- How call WordPress shortcode inside function file
- strict custom php script on specific product category [closed]
- Change WooCommerce Order status from frontend form submitted data
- How to change product title color in shop page if product has specific product tag (Woocommerce)?