I think you'll need to learn a bit of PHP for this.
First of all your text area (bob, I presume) should be set up as an option for the product with a type of "Textarea". Then set the product's price to be whatever the price per word is.
In catalog/controller/product/product.php, you need to add the following code:
$this->data['word_price'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'));
In your product.tpl make sure where the price is displayed is encapsulated by <span id="product_price">xxx</span>
Then in your javascript function counter()
at the beginning
var word_price = <?php echo (float)$word_price; ?>;
(Though you'll need to first take your function out of count.js and put it in the product.tpl inside <script>
tags)
And at the end of the function counter()
$('#product_price').val(word_price * wordCount);
That will get it displaying on the product detail page.
You'll also need to make changes in /system/engine/cart.php to calculate the price again when it gets added to the cart. (You don't want the browser to be telling your system what the price is!)
In function getProducts()
in the following if
statement..
elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') {
Remove the check for textarea.
Then after that elseif
, add another:
elseif ($option_query->row['type'] == 'textarea') {
$word_count = $this->countWords($option_value);
(countWords()
is a private function you have to add in this cart.php file but you seem to have a handle on that already as you have it in your javascript)
$product_price = $word_count * $product_query->row['price'];
$option_data[] = array(
'product_option_id' => $product_option_id,
'product_option_value_id' => '',
'option_id' => $option_query->row['option_id'],
'option_value_id' => '',
'name' => $option_query->row['name'],
'option_value' => $option_value,
'type' => $option_query->row['type'],
'quantity' => '',
'subtract' => '',
'price' => '',
'price_prefix' => '',
'points' => '',
'points_prefix' => '',
'weight' => '',
'weight_prefix' => ''
);
}
Then below that entire loop where you see
$price = $product_query->row['price'];
Replace with:
if (isset($product_price))
$price = $product_price;
else
$price = $product_query->row['price'];
Obviously the code needs cleaning up and I haven't tested it at all (e.g. it will trigger for all textarea options), but that's how I'd approach it. Though I'm not sure if it's much help if as you say your PHP knowledge is minimal.