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
- 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
- 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?
- How to get the original price of the product in woocommerce?
- 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 do i wrap woocomerce attribute in list?
- Removing files programmatically
- How to add aria role and schema markup to custom walker container
- Must filter functions receive all arguments passed to them?
- Custom Taxonomy Select Menu: Setting default option value?
- Execute PHP code only with specific user role
- User filter posts by year
- Woocommerce order status payment
- Modify WooCommerce used to get all orders in dashboard
- Output product category link from WP_Query
- How to sort WooCommerce products page by latest in-stock items first?
- Variation prices breakdown only for single product page
- Woocommerce My acount page
- Woocommerce – Exclude variation attribute on specific variation
- 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?
- PHP function for horizontal Woocommerce thumbnails and badges
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- 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
- Hide payment method based on user role AND minimum cart value
- WooCommerce display price before add to cart [closed]
- 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”
- Woocommerce – if selected attribute term equals
- split 1 cart item into instock and back ordered
- How to bind each “the_content” elements to a custom variables
- Adding product permalink on admin order page throwing error
- Add Product Permalink in woocommerce admin order page
- 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
- Custom Bulk Actions handler not firing
- 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.
- str_replace not preserving whitespace
- Use WP_Query Data In Cookie
- Limit Taxonomy Parents
- Display a post based on its metabox selection
- Search box background on a different page template
- 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
- AJAX: WordPress filters inside $html do not work as intended
- 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
- Warning: Attempt to read property “term_id” on int – Woocommerce
- 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
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- Automatically change insurance quantity based on cart total [closed]
- 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 pass value to add_filter wpcf7_form_tag from another function?
- Is there a hook that I can use when a fatal error occurs?
- Unable to logout correctly after wp-login file was modified
- Woocomerce custom add to cart button edit functionality [closed]
- How to change product title color in shop page if product has specific product tag (Woocommerce)?
- Adding Author Filter to CPTs
- How can I display formatted content using the_content filter?
- How to capture number input from wordpress form into acf field in woocommerce
- How to get default variation ID (woocommerce)