There is method on product class that is called is_on_sale()
which actually determines if the product is on sale or not. You can access it from global $product
variable. And must echo
the do_shortcode
. So the whole code will be like-
add_action('woocommerce_single_product_summary','add_product_signup', 10, 2);
function add_product_signup() {
global $product;
if( $product->is_on_sale() ) {
echo do_shortcode('[contact-form-7 id="20709" title="Product Sale Notification Signup"]');
}
}
The above code is tested. I tested it personally and it worked pretty well.
Related Posts:
- Trouble understanding apply_filters()
- How many filter/action hooks are healthy?
- Earliest hook to reliably get $post/$posts
- How to pass/get data to/from the WooCommerce data-product_variations object?
- What does (10, 2) mean when used with add_filter
- Valid characters for actions, hooks and filters
- How to check if a hook is hooked or not?
- Filter hook before create order WooCommerce
- How to make post and comment count unclickable with dashboard_glance_items hook
- How to change Woocommerce breadcrumbs content?
- Hook into admin post list page
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- About Hooks and Filters
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- Please explain me what the do_action does
- Too many actions/filters!
- How to get list of all hooks of current theme / plugin?
- How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks
- Conditionally call add_action depending on post_type?
- Woocommerce – Hide a Column in Cart Table
- Is there a Woocommerce hook that fires when applying a coupon but before checking if it’s valid?
- What is the action hook for an order that fails on frontend checkout in WooCommerce?
- Is it possible to track down Actions and Filters?
- When to use actions and when to use filters
- Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?
- Same Conditionals Not Working on Two Different Hooks
- How to call a function or method that is Namespaced using another plugin
- How to change currency programmatically on creating order action?
- add filter login_redirect does not contain original requested redirect
- get_header and hook avoid normal call
- Can the wp_filter object hold multiple values with the same key
- How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?
- apply_filters/do_action tag characters limit
- Filter taxonomy admin pagination
- Insert term when page is published – avoid duplicates after edits
- Capture post content before page renders
- How to remove action with slashes and arrows?
- Add default user field to WooCommerce checkout [closed]
- Changing WordPress core without hacking core
- Comment search plugin
- Woocommerce “added to cart” message on main(home) page
- How can I output all apply_filters and do_action?
- Remove actions/filters that are set with create_function()
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- Remove tags without a specific meta key from “choose from the most used tags”
- Redirect to woocommerce checkout after adding to cart – item already in cart
- What is the action hook to use if you want to capture the new password during password change?
- Use has_filter on comment_post
- How can I edit comment meta value before it is saved?
- Action hook to control access to certain parts of my site
- Display custom product option in admin order details
- Replace Data In Post & Update Meta Field Post Is Saved
- style_loader_tag not changing stylesheet to preload
- Hook to change the site URL
- Hook to add content after date in post?
- Put data in my-account/view-order/id/ page
- Hook inside a hook
- How to add custom checkout field in user details mail template
- WooCommerce comments_template Filter Not Firing
- Can you call a filter hook by “add_action”?
- Is it possible to use object in add_action?
- How to add attribute to output with wp_video_shortcode add_filter
- PHP5, Inheritance, Singleton – action & filter hook limitations
- Is it possible to Hook/Filters Attachment Creation?
- Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu
- How to hook some Unicode texts into calendar widget safely?
- How to add attributes to tag when template cannot be directly modified
- How to get current action?
- WordPress tag cloud add more links
- Add my own function to existing WooCommerce hook
- Yoast SEO hooks overriding themselves
- Question about how do wordpress filters/actions work
- How to center oEmbedded content
- How to change the order of HTML output of a core block?
- How to add ‘total’ value to custom column title on the posts list page
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- When to use add_action when registering/enqueuing scripts
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- How to properly modify WP Vary or any existing headers?
- Execute JavaScript in WordPress Hook
- Disadvantage of using filters & hooks multiple times
- Admin post list – adding an option to the date filter dropdown
- password_reset doesnt work
- Alter existing page contents based on url
- Add/remove CRON action depending on variable
- Register new user, assign custom role then send email
- What is the action or filter for adding information under the Permalink in Edit Post/Page?
- output custom Posts on a Page
- Add an attribute to the root from functions.php with add_filter
- Would like to use hook or filters to customize email templates
- Overriding Plugin function in your child theme
- add_action with associative array
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- wp_editor customization
- Passing a parameter to filter and action functions
- What problems could happen if I replaced add_filter and add_action with the function calling
- Adding to an array & passing it through do_action/apply_filters
- Is it possible to make get variable out of filter in Class?
- How do you disable the verification process of user email changes?