There was an error in my code. From here: http://www.sitepoint.com/woocommerce-actions-and-filters-manipulate-cart/
Changing
// correct quantity
unset( $woocommerce->cart->cart_contents[$product_id] );
$woocommerce->cart->add_to_cart( $product_id, $quantity );
To
// correct quantity
// Get it's unique ID within the Cart
$prod_unique_id = $woocommerce->cart->generate_cart_id( $product_id );
// Remove it from the cart by un-setting it
unset( $woocommerce->cart->cart_contents[$prod_unique_id] );
$woocommerce->cart->add_to_cart( $product_id, $quantity );
Has worked.
Related Posts:
- Woocommerce add to simple product attribute programmatically [closed]
- Creating loop within functions.php
- 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]
- When sale price is 0.00 show only regular price
- Create custom function for hero image
- Parent category as WOOCommerce Categories widget title
- Woocommerce custom calculation function
- Copy and Modified WooCommerce function is_coupon_valid [closed]
- Add multiple custom fields to the general settings page
- How to display custom field in woocommerce orders in admin panel?
- Is it possible to remove the “standard” post format?
- Issue with get_theme_mod returning a blank value instead of the saved value
- How to remove row-actions from pages table?
- Modify search function in WordPress (TwentyTwelve)
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- How to fix a theme with page.php Default Template that accidentally deleted?
- How to Acheive the custom woocommerce category template
- How do I change parameters without changing the core
- Problem with extract() with custom shortcode
- Remove product description from product archive page
- Hide some items from Screen options in dashboard for products
- add sidebar area to header of child theme
- Can you use admin pages functionality on the frontend of your site
- Theme-Config tab in admin Pannel?
- Display WooCommerce subscriptions for user [closed]
- Increment price for Woocommerce Minicart [closed]
- Change woocommerce products weight varation based its product category or tags? [closed]
- adding custom classes for tables
- Pass Shortcode Attribute to footer Script
- Woocommerce checkout field maxlength, make input number field only (postcode)
- PHP files included in functions.php don’t seem to work
- change in form-checkout.php by using code in functions.php
- How Can I Expand the WordPress Customize window without any Plugin?
- Automatically wrap multiple images in div
- Ajax not working properly
- How to display custom option field in woocommerce orders in admin panel?
- Best practices regarding the creation of custom widgets?
- Remove the product category module block from the Woocommerce product page
- different style sheet for just one page template
- Functions when woocommerce isn’t installed
- How to change this simple code so that it sends the email notification after payment in WooCommerce?
- replace text in Sort Box
- login_headertitle is deprecated since version 5.2.0
- add referrer to woo
- Add attribute only to first image of every post via functions.php
- Different favicon on different pages
- The_content and Preg_replace in loaded Iframe [closed]
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- Adding product to WooCommerce cart [closed]
- two search forms on the same page
- WooCommerce -> wc_enqueue_js not working [closed]
- Use existing image sizes for WooCommerce
- Insert a field with PREG_REPLACE – strange behaviour
- How to echo Widget Title in Custom Frontend-Template Box
- how to display a page before the home page
- loginout function customization
- Function to check if custom page is used by page?
- implementing a centralized content “show-do-not-show” toggle?
- How would I make a function to dynamically determine if user is logged to change navigation menu text?
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- WordPress – using sessions?
- Customise Grouped Product display in Woocommerce with custom column
- Woocommerce Variable Product Dropdown for Custom Shop Template
- How to hide content on mobile in the functions.php file – woocommerce
- How to remove font awesome from loading in wp theme
- Header menu aligned right on all pages except for single-post page [closed]
- Hide ‘add to cart’ when certain value in dropdown is selected
- Adding discount functionality to the cart
- Remove text after a dot and a colon in Woocommerce product title
- Woocommerce product price change
- Help with with my function for wordpress
- Remove clickable Link of WordPress Site Logo from Woocommerce Single Product page
- Problems adding a new field to product in cart
- Extend WordPress Audio Widget to accept HLS (.m3u8) URLs
- Shortcode to insert default text and change one word throughout it?
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- Variable function names
- Woocommerce – Switching Price for Category
- add product thumbnail to checkout page only and include variation name
- WordPress Ajaxifying not working properly
- WordPress function with attribute pass to template
- Move product attributes after summary on single product page
- Will dequeueing in child theme functions.php file prevent Google Fonts from loading?
- Which method is more correct for removing WooCommerce Extensions menu item?
- Adding A New Widget to WordPress Disables the Existing Widgets
- Help! Need a different logo on my main page from my other pages
- Display page number on custom page title function
- How to replace words in my posts and saved new words
- Shortcode to eliminate and replace with
- Insert menu into theme location depending on user logged in/out status
- Add functionality to post editor
- Why does modifying my functions.php file always result in a server error
- Remove snippets of JS from core
- reusing code in function and running it with loop
- Explode Array from Repeatable Custom Field
- Problem with removing characters “<” – WpAllImport
- multible shortcodes (for differnt values) with one function
- woocommerce_sort_product_tabs() expects an array
- sort by date in users
- Customizer cuistom CSS Priority ordre Issue