Set quantity of woocommerce product on page visit [closed]

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.

tech