Why do you think you need to change the way the price is returned? The original function gives the attribute price based on its calculation of the number of words x price per word; you should be able to return the correct square foot price by calculating the number of square feet x the price per square foot. The product's base price doesn't need to enter into it, if you have the product set up correctly.
We need to know exactly how you have the product configured *and* how you want it to behave to advise on why it isn't working, though I suspect you have a nonzero base price and are trying to replace that with the calculated square foot price.
PHP Code:
// calculate words price
function zen_get_word_count_price($string, $free=0, $price) {
$word_count = zen_get_word_count($string, $free);
if ($word_count >= 1) {
return ($word_count * $price);
} else {
return 0;
}
}
PHP Code:
function zen_get_word_count_price($string, $free=0, $price) {
$actual_price = zen_get_products_actual_price($products_id);
$squareFoot = explode("x",$string);
if($squareFoot[0]<0||$squareFoot[1]<0) {
return 0;
} else if($squareFoot[0]>50||$squareFoot[1]>10){
return 0;
} else if(count($squareFoot) == 1){
return 0;
}else{
$pricePerSqFoot = ($squareFoot[0] * $squareFoot[1] * $price -$actual_price);
return $pricePerSqFoot;
}
}
Try this, with the product price set to 0, "priced by attributes", and the attribute price set to the square foot base:
PHP Code:
function zen_get_word_count_price($string, $free=0, $price) {
$squareFoot = explode("x",$string);
if($squareFoot[0]<0||$squareFoot[1]<0) {
return 0;
} else if($squareFoot[0]>50||$squareFoot[1]>10){
return 0;
} else if(count($squareFoot) == 1){
return 0;
}else{
$sqFootPrice = ($squareFoot[0] * $squareFoot[1] * $price);
return $sqFootPrice;
}
}
Seeing it in action may be helpful.
Bookmarks