If you have defined the class MyCart
directly in functions.php
with your hooks. I’d expect for the following to work:
// add action
$cart = new MyCart();
function emdr_add_to_cart(){
$items = $cartClass->get_users_cart_contents();
// process items
}
add_action( 'woocommerce_add_to_cart', 'emdr_add_to_cart');
I might also add that duplicating the “state” of the users cart in 2 places is probably a code smell. I would suggest using the values directly from the WooCommerce cart.
Related Posts:
- Does an activated plugin automatically mean its methods are available to other WP functions?
- Use wc_enqueue_js only on specific pages – nested add_action
- How to Remove a Filter from the Admin List Table?
- Extend a class of a plugin
- Trying to place a custom field after the total section in the checkout page in woocommerce
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- Display attribute on shop page after the title
- Woocommerce custom Plugin in wordpress [closed]
- How do I remove an action hook inside a class that is called by another class?
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- How to add custom checkout field in user details mail template
- How to add product in woocommerce with php code [closed]
- How to add date range in woocommerce with code
- Creating custom Woocommerce attribute taxonomies from a plugin
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to get the original price of the product in woocommerce?
- Woocommerce, recognize the loop of related products
- Remove commas from WooCommerce checkout addresses fields
- WooCommerce Link to Product Category
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Writing scripts using WordPress / WooCommerce classes?
- How to make custom total price reactive in navigation
- Change description on specific WooCommerce product status change
- Woocommerce – Filter Variable Products by Variation Attributes and Variations Regular Price
- How to add a second ‘place order’ button in WooCommerce [closed]
- Woocommerce redirect thankyou page based on product ID doesn’t empty Cart
- tracking number field in Woocommerce order [closed]
- WooCommerce Related Products by Attribute
- Image as Sales Badge
- add_action shortcut?
- Modify HTML structure of fields in woocommerce checkout form
- Add a product to checkout via form
- WordPress default Search function inconsistent in WooCommerce Product Titles
- How can I get the values of my WordPress $wpdb query in Jquery?
- Trouble checking if custom woocommerce checkout field is empty or not
- Adding function to Genesis genesis_header [closed]
- My new button is in the wrong place
- jQuery code not working when included in functions.php
- Function returns text instead of html [closed]
- Undefined method class::construct() when creating a plugin
- require_once() if a product in woocommerce contains a tag [closed]
- How to display SQL query that ran in WC_Order_Query?
- How to disable delivery on certain date at checkout page in WooCommerce?
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- Call WC_Product get_price()?
- Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- woocommerce wc_create_order(); is creating multiple orders instead of one?
- How to work Woocommerce pagination inside shortcode?
- How to restrict shipping zone in a specific interval time
- Hide specific product from Woocommerce if the logged-in user has already enrolled into the course
- Convert a column of a table containing an Array as response in HTML
- Display custom field value in woocommerce variable product via jQurey
- Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
- Change the URL of an image from wp_get_attachment_image_src for Product Posts based on Category
- get orders of today’s date
- product_type_options get saved value [closed]
- How to retrieve quantity input field by id in woocommerce
- Get only relevant sub-category of category “Genre” that applies to current product only
- Using zip code to display custom data in Admin Order Details
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Including user data in “new user notification email”
- Add Shortcode to ::before class
- i want add conditional for add category in wordpress
- WooCommerce get products based on the taxonomy
- Woocommerce Add custom “Add to cart button” in single page with tags
- Woocommerce remove menu item on myaccount dashboard
- Hook into all password resets in WordPress and get password before hashing?
- Why should I need to add init action to include PHP file to WordPress Plugin?
- append data to mysql table via submit button coded in php – not working
- random woocommerce categories are not showing when count enabled?
- remove_action() not working in page template – Genesis
- How to hook into the subscriber /wp-admin/index.php page?
- PHP – Woocommerce 3.2 Add variable shipping insurance with multiple “else if ” conditions
- how to display woocomerce description of each category in wordpress? [closed]
- WordPress 3.0 PHP Error – notice WordPress_product_Type was called incorrectly
- Add two or multiple functions in WordPress Post or Page
- Submit to itself don’t work
- WooCommerce – Add product category below product price [closed]
- woocommerce plugin bugs
- Adding my own custom template page but got white page
- Woocommerce Price Text
- WordPress HTML Helper
- Property value of null when value is assigned inside a method hooked to the wp action hook
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- wc_add_notice not working on cart page
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How do I update product shipping using PHP in WooCommerce?
- How can I edit the WooCommerce Mini DropDown Cart to read as follows
- Show button in header when product custom field is not empty
- Why a class property becomes empty?
- WordPress 6.1.1 UTF8 Slug Limit Increase
- How to change wp-admin and wp-login urls
- Woocommerce Convert existing order to the cart
- How to change shipping method title based on cart amount?
- How to add SKU and remove product title from WooCommerce url?
- Product Search in search.php
- using custom pages for myaccount in woocommerce