Going by your method I would suggest hooking into wp_footer
as well, so that your script would be near the end of the body, that way it will be loaded after all DOM was loaded.
add_action('woocommerce_ajax_added_to_cart', 'set_button_classes');
function set_button_classes () {
add_action('wp_footer', function () {
echo "<script>document.getElementByClassName('added_to_cart wc-forward').classList.add('ct-cart-item', 'ct-offcanvas-trigger');</script>";
});
}
You could also close the php tag and reopen it in the wp_footer
anonymos function to make it easier to understand/see the scrip code
add_action('woocommerce_ajax_added_to_cart', 'set_button_classes');
function set_button_classes () {
add_action('wp_footer', function () {
?>
<script>
document.getElementByClassName('added_to_cart wc-forward').classList.add('ct-cart-item', 'ct-offcanvas-trigger');
</script>
<?php
});
}
Related Posts:
- Javascript / Ajax Error After Migrating To New Domain Name
- Running JavaScript after using WooCommerce Filter Plugin
- woocommerce deposit Form with AJAX and shortcode won’t update but add to previous output
- List of JS events in the WooCommerce frontend
- How to save Clicks of a download link button while it doesn’t matter if we refresh the page or again login/logout
- Hide Add to Cart Button
- WooCommerce add_to_cart() with custom price [closed]
- wc_get_product in a none woocommerce page
- WooCommerce add_to_cart url not working [closed]
- Mini cart in header using divi is not getting updated on changing the cart items count:
- How to make custom total price reactive in navigation
- How to stop a Gutenberg Block from firing multiple GET Requests?
- How to prevent those PHP variables from being cached on WordPress?
- Woocommerce Ajax Add cart not working
- “Cannot read property ‘replace’ of undefined” Javascript error when trying to add attribute terms from add product page [closed]
- woocommerce_package_rates not fired everytime
- Problems adding in-store product managers
- Status 400 for AJAX POST Request with admin-ajax.php
- How can i stop woocommerce checkout event based on api request result?
- Programatically Remove Item from Cart Not Working – Needs Page Refresh
- adding a script with type=”module” to woocommerce admin area
- Force uppercase on some WooCommerce checkout fields input
- In WooCommerce product archive, how can you also set the quantity to be added to cart by typing, instead of just by using +/-?
- WooCommerce update_shipping_method ajax call wipes shipping method set on non-checkout page [closed]
- WooCommerce Ajax Cart Update Stopped Working
- Javascript error when adding an item to the cart [closed]
- CF7 Ajax isn’t working when called inside WooCommerce “woocommerce_before_add_to_cart_button” hook [closed]
- ajax request in wordpress
- WooCommerce event works in jQuery but not in JavaScript
- Add to cart – button should be disabled
- Using the WordPress and WooCommerce REST APIs in the same Node app
- Woocommerce variable product’s total amount by javascript
- Ajax add to cart not updating Elementor mini cart totals
- List of JS events in the WooCommerce frontend
- Woocommerce Checkout Page Total Price Inside Google Pay Script
- WooCommerce variable product can not add to cart using ajax after updating latest version of WooCommerce
- call_user_func_array() expects parameter 1 to be a valid callback, class ‘WC_Rapyd’ does not have a method ‘install’
- Call product search from custom hook
- Deregister dequeue JS scripts except on 1 product page
- How to make wocommerce shop products same heigt
- Woocommerce Variation product added twice to cart
- woocommerce REST api on the website’s front-end
- Format number to 2 decimal places
- Woocommerce Multisite global search how to mod ajax function?
- Pass values to ajax
- Unable to call woocommerce hook in my custom php file
- Fragments to Update Cart Counter not working on homepage – Woocommerce
- Overriding Plugin function in your child theme
- Update / refresh mini cart, after custom AJAX add_to_cart event
- AJAX to add to cart multiple products woocommerce
- Can’t update WooCommerce payment method title
- currentURL is not defined
- Using category and its sub-categories products attributes as filter in products pages
- Retrieve Woocommerce Cart Url with javascript/jquery [closed]
- Removing Product from Woocommerce checkout page using Ajax
- How to echo a PHP code into WooCommerce variation product?
- add_filter not works in ajax
- SyntaxError: unterminated string literal – if WordPress Debug in wp-config is set to true
- How to insert link, with lightbox, that opens specific page content only
- How to add ajax loading icon after click add to cart button on woocommerce
- Woocommerce custom product with JS script, can’t understand how it works [closed]
- Removing ‘woocommerce-no-js’ class from body
- WordPress error
- Trigger a JavaScript function based on the data fetched from Woo commerce hook
- Remove Woocommerce product from cart with ajax/fetch
- WooCommerce Modal Fly cart on add to cart – With AJAX
- Woocommerce ajax search can’t work on mobile
- How do I fix this “Uncaught ReferenceError: woodmartThemeModule is not defined”?
- Loading specific ajax from a product
- WooCommerce Order Sync via Custom REST API Endpoint Failing
- How to avoid double add to cart AJAX Add to card Woocommerce?
- Update a server-side render Block when woocommerce cart block changed
- How to detect changes in WooCommerce store (react)?
- WooCommerce custom SVG coloring tool [closed]
- Fatal error: Uncaught Error: The script tried to modify a property on an incomplete object
- Woocommerce product not responsive
- How to make this shortcode not refresh the whole page when i use it on frontend
- he slug “sub category” is already in use by another term
- How to disable the autozoom on mouseover for the product image in Storefront theme of WooCommerce?
- Cannot use dynamic prefix for WooCommerce permalink
- Woocommerce paginate link generates #038 instead of ? – seems connected to caching
- limit all products
- Pricing Rules plugin bulk table not showing in varition of products (have 2 attributes) if single attribute its shows
- how to refrence woocommerce blocks in code?
- How to show custom fields in modal in category page
- Wocommerce single product custom design with different attributes using drop down
- Woocomerce: Php code displayed on Product detail page
- How to make the product single photos vertical? (woocommerce)
- Filtering by Hard-coded WooCommerce Product Attributes
- Wp Redirect Not Working Can u Help
- Recalculate Completed Orders on WooCommerce to subtract Tax from Order Total
- How to address an invalid “NOT IN ()” query?
- I want to change the products I created with Advanced Custom Field to Woocommerce Product attribute
- Product reviews in my sql database
- Implement AJAX ‘load more’ with offset posts
- Woocommerce – how can i add items to cart using onclick – multiple items at once with custom prices
- Creating WooCommerce product variations programatically not bounding a particular attribute to a particular variation
- Email Woocommerce customer a link to login and set a password for their automatically created account
- WooCommerce wrong language
- How to implement my product variations/attributes in my contact form 7 email?