|
/ Documentation /Developers/ How to Display a Call-to-action when a Specific Product is Added to the Cart?

How to Display a Call-to-action when a Specific Product is Added to the Cart?

If you want to trigger a call-to-action when a specific product is added to the cart, you just need to add the following code snippet in your theme’s functions.php file.

add_filter( 'cp_pro_target_page_settings', 'cp_is_display_popup', 10, 2 );

function cp_is_display_popup( $display_style, $style_id ) {
     // if style is to display on this page ( replace 7 with your style id ) 
     if( $display_style && 7 == $style_id ) {
         global $woocommerce;
         $display_style = false;
         foreach( $woocommerce->cart->get_cart() as $key => $val ) { 
             $_product = $val['data']; 
             // replace 10 with your product id
             if( 10 == $_product->get_id() ) {
                 // display style
                 $display_style = true;    
             }  
         }  
     }
     return $display_style;
 }
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
On this page

🔥 Extended Cyber Savings: Shop Before It’s Gone!

00
Months
00
Days
00
Hours
00
Minutes
00
Seconds

WAIT!!

You’re Missing the Biggest Discount of the Year!

00
Months
00
Days
00
Hours
00
Minutes
00
Seconds

Grab this rare opportunity to save up to 30%

100% Risk-Free Money Back Guarantee!

Compare Convert Pro with...

29439
29440
Scroll to Top