Skip to content

Instantly share code, notes, and snippets.

@NorthTexasCreative
Last active October 26, 2022 15:30
Show Gist options
  • Save NorthTexasCreative/0260876bc45d0c9adef230df11cd47db to your computer and use it in GitHub Desktop.
Save NorthTexasCreative/0260876bc45d0c9adef230df11cd47db to your computer and use it in GitHub Desktop.
Force add to cart quantity to 1 and disable +- quantity input
/**
* @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' );
//remove message CONTINUE SHOPPING after an item has been added to cart
function filter_wc_add_to_cart_message_html( $message, $products ) {
return "<span>".$message."</span>";
};
add_filter( 'wc_add_to_cart_message_html', 'filter_wc_add_to_cart_message_html', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment