0

I'm building an ecommerce site where some products are price negotiable and want a way to add POA instead of a listing a price when a product is displayed.

I'm kinda surprised at how hard this is to do.. I have a snippet that works for Ubercart 1 in Drupal 5, but it looks like the hooks have changed in Ubercart 3 and I can't find a pricing hook:

    <?php
function zen_uc_product_display_price($price) {
  $output = '<div class="display_price">';
    if ($price!=0) {
      $output .= uc_currency_format($price);
    } else {
      $output .= t('P.O.A');
    }
  $output .= '</div>';
  return $output;
}
function

zen_uc_product_sell_price($price, $teaser) {
  if ($teaser) {
    $output = '<span class="sell_price">';
        if ($price!=0) {
            $output .= uc_currency_format($price);
        } else {
            $output .= t('P.O.A');
        }
    $output .= '</span>';
  }
  else {
    $output = '<div class="sell_price">';
        if ($price!=0) {
            $output .= t('Price: !price', array('!price' => uc_currency_format($price)));
        } else {
            $output .= t('Price: P.O.A');
        }
    $output .= '</div>';
  }
  return $output;
}
?>

I've managed to hook the add to cart function and direct it to a webform with the following snippet:

<?php

function fmc_uc_product_add_to_cart( $variables ) {
$sell_price = $variables['form']['node']['#value']->price;
if ($sell_price <= 0) { 
return '<form action="http://www.example.com/" method="post"><input type="hidden" name="product" value="' . drupal_get_title() . '" /><input type="submit" class="form-submit" value="' . t('POA') . '" /></form>';
}
else {
return fmc_uc_product_add_to_cart($variables);
}
}

But I'm having no luck with the pricing function, if anyones got a code snippet I can run in my template.php file that'd be the ideal solution, but any ideas / advice is hugely appreciated. Is there a way this can be broken out inside a node--product.tpl.php file maybe?

1

I have not tried this out but I would think you could override theme_uc_price() in your template.php something like this:

function THEMENAME_uc_price($variables) {
  if ($variables['price']) {
    $output = '<span class="uc-price">' . uc_currency_format($variables['price']) . '</span>';
    if (!empty($variables['suffixes'])) {
      $output .= '<span class="price-suffixes">' . implode(' ', $variables['suffixes']) . '</span>';
    }
  }
  else {
    $output = t('P.O.A');
  }
  return $output;
}
| improve this answer | |
  • Perfect solution! – JamiePatt Jan 30 '15 at 14:12
  • Oops... actually, I spoke to soon, something in this code is causing an internal server error for anything that does have a price... It works perfectly for items of $0 but kills anything that has a value for price. – JamiePatt Jan 30 '15 at 22:10
  • What is the error in the web server log? – rooby Jan 31 '15 at 4:24
0

I finally managed to get this to work for me in Drupal 7/Ubercart 3 for an art gallery where we wanted POA to display for $0.00 and the price to display for priced items. The code below goes in the bottom of your theme template.php file. (please note to get all the code to show on here without this forum stripping bits out, I had to remove the opening tag before span so you just need to pop that back in eg: '(less-than-sign)span in line 2. Also right near the end replace '(less-than-sign)/div> as per this screenshot. Code to copy is below.

enter image description here

Hope this saves someone some hours!

    /* change uc price to show POA if price is zero */

 function YOURTHEMENAME_uc_price($variables) {
$output = 'span class="uc-price">';

if ($variables['price']!=0) {

  $output .= uc_currency_format($variables['price']);
} else {
  $output .= t('P.O.A');
}

$output .= '/div>'; return $output;

}

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.