Hi,
In your code, the important part is:
if(!empty($product->left2) && !empty($product->right2)){
$quantity = $quantity*2;
}
There, you basically say: when the custom fields "left2" and "right2" have been filled/selected, multiple the quantity of the product by 2.
But you actually don't use the values selected in the fields. Please look again at the code of the plugin we provide in our FAQ. You'll see there that we do use the values of the fields to update the quantity:
$quantity = $quantity*$product->length*$product->width;