Created
October 2, 2022 22:06
-
-
Save NorthTexasCreative/98c364565c3afb743feaa6ef56fc961f to your computer and use it in GitHub Desktop.
Individual Cart Item Display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @snippet WooCommerce Display Separate Cart Items for Product Quantity > 1 | |
* @author Carla Chalmers | |
* @testedwith WooCommerce 3.5.1 | |
*/ | |
// ------------------- | |
// Split product quantities into multiple cart items | |
// Note: this is not retroactive - empty cart before testing | |
function split_product_individual_cart_items( $cart_item_data, $product_id ) { | |
$unique_cart_item_key = uniqid(); | |
$cart_item_data['unique_key'] = $unique_cart_item_key; | |
return $cart_item_data; | |
} | |
add_filter( 'woocommerce_add_cart_item_data', 'split_product_individual_cart_items', 10, 2 ); | |
// ------------------- | |
// Force add to cart quantity to 1 and disable +- quantity input | |
// Note: product can still be added multiple times to cart | |
add_filter( 'woocommerce_is_sold_individually', '__return_true' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment