From a cursory overview, the cross-sells are added via the same ajax add to cart script as regular shop loop archive products and I don’t see a way to distinguish between when it’s a cross-sell and when it’s not. You could run a script conditionally only on the cart page, and then listen to the added_to_cart trigger, which might then only be happening for cross sells (assuming you don’t have other ajax add to cart buttons on the cart page)
Or it appears that the add to cart button is passed as a variable to the added_to_cart
trigger. You may be able to do some DOM manipulation there to see if it was part of the cross sells div. Totally wild guess:
$( document.body ).on( 'added_to_cart', function( event, fragments, cart_hash, $button ){
if( $button.closest( 'div.cross-sells' ) ) {
// was a cross-sell added to the cart
}
});
Related Posts:
- Apply jquery script to only woocommerce product pages and categories
- woocommerce target button with class after ajax update
- Woocommerce checkout field maxlength, make input number field only (postcode)
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- Hide ‘add to cart’ when certain value in dropdown is selected
- How to run a function every 5 minutes?
- How to display custom field in woocommerce orders in admin panel?
- How to create a custom order status in woocommerce!
- How to show product SKU on product page
- How to get woocommerce inventory status [closed]
- Woocommerce add to simple product attribute programmatically [closed]
- AJAX handler throws 400 (Bad request) – why?
- ajax live search for post title
- In WooCommerce I need to modify the thankyou.php page [closed]
- How can I add an extra WooCommerce hook
- Replacing select2 in admin backend for all selects
- How to save Uploaded image in custom option panel?
- How to Acheive the custom woocommerce category template
- Remove product description from product archive page
- Hide some items from Screen options in dashboard for products
- display 100 products per page on product category page [closed]
- jQuery plugin function is not a function
- Adding WooCommerce to a Custom Theme – not working [closed]
- Issue adding text after short description on product pages Woocommerce [closed]
- Display a function using AJAX
- Enqueuing Script in functions.php vs on the page
- Exclude Empty Child Categories in Menu
- Can you use admin pages functionality on the frontend of your site
- Unable to get_the_content(); of a post in WordPress via AJAX
- change billing and shipping address 1 and 2 field placeholders [closed]
- Add external js file to footer with id
- Creating loop within functions.php
- Ajaxing function in widget class
- How to load some jquery code to make validation in the theme customizer?
- Override woocommerce wc-class function
- Display WooCommerce subscriptions for user [closed]
- Increment price for Woocommerce Minicart [closed]
- Change woocommerce products weight varation based its product category or tags? [closed]
- Move jQuery and Migrate to footer?
- jquery won’t load in footer
- WordPress doesn’t Load JQuery Now? Do I need to enqueue JQuery also?
- WordPress function for 1 to for many
- Pass parameters to function through an action
- change in form-checkout.php by using code in functions.php
- Set quantity of woocommerce product on page visit [closed]
- Replace menu links with # and add name to its li
- Product Tags in Add New product as checkbox list [closed]
- WooCommerce – Reset quantity input field when variation changes
- Calling a function from anywhere, used in different places
- Selective Product Category for Carousel
- Loading CDN that requires jQuery in WordPress
- I want to get product attirbute in the section below
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Right way to update widget on dynamic new input field
- How to load jQuery in the footer – nothing works for me
- Not sure if enqueuing js scripts properly
- How can I remove the main description text box in a Woocommerce product editor page? I only use the “Product short description” text box [closed]
- Wp_query function to search from product_title ‘OR’ product tags name
- Allow Post Author to be 0 on Update
- Load Woocommerce and WordPress Functions Outside
- Trouble with adding a wp_enqueue_script on wordpress
- WP Ajax Function Always Returning undefined
- How to display custom option field in woocommerce orders in admin panel?
- Scripts not appending to element in AJAX call – why?
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to add a slide toggle to the Woocommerce-Layout__Activity-Panel area in the orders admin page
- Add to cart php not working [closed]
- Wp_schedule_event functions.php
- How to auto refresh when user change postcode
- When sale price is 0.00 show only regular price
- Remove the product category module block from the Woocommerce product page
- How can I get the values of my WordPress $wpdb query in Jquery?
- how can I edit flexslider in woocommerce. [Urgent]
- How to change the order of Jquery in the footer of my theme?
- How to search using ajax for exact phrase or words in an input field?
- how to en-queue jQuery to load before the tag
- Jquery implementation not working on page reload
- woocommerce change currency per category [closed]
- I can’t enqueue my scripts – They literally aren’t being added to my site
- Attempt to change jQuery version caused White Screen of Death
- PHP mixed with some JS code to update WordPress theme settings
- Load jquery only for certain pages in the backend
- Change CSS for logged in users
- Always the Latest google jQuery instead of default WordPress jQuery
- Add a jQuery Function
- jQuery does not work
- using jQuery on only one page
- help I changed one currency in woocommerce and everything is ruined [closed]
- Functions when woocommerce isn’t installed
- How to override woocommerce.css?
- Can’t call Javascript function – scope?
- How can I use Woocommerce $product->get_attribute in functions.php? (if at all)
- How to change this simple code so that it sends the email notification after payment in WooCommerce?
- Changing parent element’s class or style
- Enqueuing latest version of jQuery into a child theme returns a blank screen
- (Woocommerce) Order by price when entering specific category
- echo custom fields with AJAX
- Adding jQuery datepicker to Custom Post Type Metabox [closed]
- In jquery use php variable to execute an enqueued jquery file
- Run a jquery script on on a certain template page