I have been working on a Gravity Forms extension for a client. The concept is to add a new field type with 4 inputs. I have tried about 10 different variations on how people build custom gravity form fields, but I keep running into the same issue.
When creating a custom field, if I use only 1 input under the naming convention of input_{field_id} the form will save and validate properly. But the moment I try to add more than one field using the names input_{field_id}.{i} just like the built in fields the form will no longer save my data.
<?php if ( ! class_exists( 'GFForms' ) ) { die(); }
class GF_Field_Attendees extends GF_Field {
public $type = 'attendees';
public function get_form_editor_field_title() { return esc_attr__( 'Attendees', 'gravityforms' ); }
public function get_form_editor_button() {
return array(
'group' => 'advanced_fields',
'text' => $this->get_form_editor_field_title(),
'onclick' => "StartAddField('".$this->type."');",
);
}
public function get_form_editor_field_settings() {
return array(
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'admin_label_setting',
'rules_setting',
'duplicate_setting',
'description_setting',
'css_class_setting',
);
}
public function is_conditional_logic_supported() { return true; }
public function get_field_input( $form, $value = '', $entry = null ) {
$form_id = $form['id'];
$field_id = intval( $this->id );
$first = esc_attr( GFForms::get( 'input_' . $this->id . '_1', $value ) );
$last = esc_attr( GFForms::get( 'input_' . $this->id . '_2', $value ) );
$email = esc_attr( GFForms::get( 'input_' . $this->id . '_3', $value ) );
$phone = esc_attr( GFForms::get( 'input_' . $this->id . '_4', $value ) );
$disabled_text = $is_form_editor ? "disabled='disabled'" : '';
$class_suffix = $is_entry_detail ? '_admin' : '';
$first_tabindex = GFCommon::get_tabindex();
$last_tabindex = GFCommon::get_tabindex();
$email_tabindex = GFCommon::get_tabindex();
$phone_tabindex = GFCommon::get_tabindex();
$required_attribute = $this->isRequired ? 'aria-required="true"' : '';
$invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
$first_markup = '<span id="input_'.$field_id.'_'.$form_id.'.1_container" class="attendees_first">';
$first_markup .= '<input type="text" name="input_'.$field_id.'.1" id="input_'.$field_id.'_'.$form_id.'_1" value="'.$first.'" aria-label="First Name" '.$first_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$first_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_1">First Name</label>';
$first_markup .= '</span>';
$last_markup = '<span id="input_'.$field_id.'_'.$form_id.'.2_container" class="attendees_last">';
$last_markup .= '<input type="text" name="input_'.$field_id.'.2" id="input_'.$field_id.'_'.$form_id.'_2" value="'.$last.'" aria-label="Last Name" '.$last_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$last_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_2">Last Name</label>';
$last_markup .= '</span>';
$email_markup = '<span id="input_'.$field_id.'_'.$form_id.'.3_container" class="attendees_email">';
$email_markup .= '<input type="text" name="input_'.$field_id.'.3" id="input_'.$field_id.'_'.$form_id.'_3" value="'.$email.'" aria-label="Email" '.$email_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$email_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_3">Email</label>';
$email_markup .= '</span>';
$phone_markup = '<span id="input_'.$field_id.'_'.$form_id.'.4_container" class="attendees_phone">';
$phone_markup .= '<input type="text" name="input_'.$field_id.'.4" id="input_'.$field_id.'_'.$form_id.'_4" value="'.$phone.'" aria-label="Phone #" '.$phone_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$phone_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_4">Phone #</label>';
$phone_markup .= '</span>';
$css_class = $this->get_css_class();
return "<div class='ginput_complex{$class_suffix} ginput_container {$css_class} gfield_trigger_change' id='{$field_id}'>
{$first_markup}
{$last_markup}
{$email_markup}
{$phone_markup}
<div class='gf_clear gf_clear_complex'></div>
</div>";
}
public function get_css_class() {
$first_input = GFFormsModel::get_input( $this, $this->id . '_2' );
$last_input = GFFormsModel::get_input( $this, $this->id . '_3' );
$email_input = GFFormsModel::get_input( $this, $this->id . '_4' );
$phone_input = GFFormsModel::get_input( $this, $this->id . '_5' );
$css_class = '';
$visible_input_count = 0;
if ( $first_input && ! rgar( $first_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_first_name ';
} else {
$css_class .= 'no_first_name ';
}
if ( $last_input && ! rgar( $last_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_last_name ';
} else {
$css_class .= 'no_last_name ';
}
if ( $email_input && ! rgar( $email_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_email ';
} else {
$css_class .= 'no_email ';
}
if ( $phone_input && ! rgar( $phone_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_phone ';
} else {
$css_class .= 'no_phone ';
}
$css_class .= "gf_attendees_has_{$visible_input_count} ginput_container_attendees ";
return trim( $css_class );
}
public function get_value_submission( $field_values, $get_from_post ) {
if(!$get_from_post) {
return $field_values;
}
return $_POST;
}
}
GF_Fields::register( new GF_Field_Attendees() );
I have spend about 20 hours trying different fixes and searching the internet to get this working, with no luck to show for it. At one point I was able to get the form fields to save using a different method (see below), but I could not make the field required or use conditional login on it, which is a must.
$group_title = "Attendees";
$group_name = "attendees";
$group_fields = array(
'attendee_first' => 'First Name',
'attendee_last' => 'Last Name',
'attendee_email' => 'Email',
'attendee_phone' => 'Phone'
);
$group_values = array();
add_filter('gform_add_field_buttons', add_field);
function add_field($field_group)
{
global $group_title, $group_name;
foreach ($field_group as &$group) {
if ($group['name'] == 'advanced_fields') {
$group['fields'][] = array (
'class' => 'button',
'value' => __($group_title, 'gravityforms'),
'onclick' => "StartAddField('".$group_name."');",
'data-type' => $group_name
);
break;
}
}
return $field_group;
}
add_filter('gform_field_type_title', add_field_title, 10, 2);
function add_field_title($title, $field_type)
{
global $group_title, $group_name;
if ($field_type == $group_name) {
$title = __($group_title, 'gravityforms');
}
return $title;
}
add_filter('gform_field_input', 'render_fields', 10, 5);
function render_fields($input, $field, $value, $entry_id, $form_id)
{
global $group_name, $group_fields;
if ($field->type == $group_name)
{
$i = 1;
$input = '<div class="ginput_complex ginput_container">';
foreach ($group_fields as $key => $val) {
$input .= '<span id="input_'.$field['id'].'_'.$form_id.'_'.$i.'_container" class="name_suffix ">';
$input .= '<input type="text" name="input_'.$field['id'].'_'.$i.'" id="input_'.$field['id'].'_'.$form_id.'_'.$i.'" value="'.$value[$field['id'].'.'.$i].'" class="'.esc_attr($key).'" aria-label="'.$val.'">';
$input .= '<label for="input_'.$field['id'].'_'.$form_id.'_'.$i.'">'.$val.'</label>';
$input .= '</span>';
$i ++;
if ($i % 10 == 0) { $i++; }
}
$input .= '</div>';
}
return $input;
}
add_action('gform_editor_js_set_default_values', set_default_values);
function set_default_values()
{
global $group_title, $group_name, $group_fields;
?>
case '<?php echo $group_name; ?>' :
field.label = '<?php _e($group_title, 'gravityforms'); ?>';
field.inputs = [
<?php
$i = 1;
foreach ($group_fields as $key => $val) { ?>
new Input(field.id + 0.<?php echo $i; ?>, '<?php echo esc_js(__($val, 'gravityforms')); ?>'),
<?php
$i++;
if ($i % 10 == 0) { $i++; }
} ?>
];
break;
<?php
}
add_filter( 'gform_entry_field_value', 'category_names', 10, 4 );
function category_names( $value, $field, $lead, $form )
{
global $group_name, $group_values;
if($field->type == $group_name)
{
$array = array();
$output = "";
foreach($field->inputs as $input)
{
$array[$input['label']] = $value[$input['id']];
$output .= "<strong>".$input['label'].":</strong> ";
$output .= $value[$input['id']]."<br>";
}
$group_values[] = $array;
return $output;
}
return $value;
}
If anyone can help me with either issue, it would be greatly appreciated.
Class update:
Cleaned Up get_field_input
Added get_value_submission
After working with the Gravity Forms support team for a few days, we were able to come up with this solution. Everything seems to be working now. Hope this helps someone in the future.
class GF_Field_Attendees extends GF_Field {
public $type = 'attendees';
public function get_form_editor_field_title() {
return esc_attr__( 'Attendees', 'gravityforms' );
}
public function get_form_editor_button() {
return array(
'group' => 'advanced_fields',
'text' => $this->get_form_editor_field_title(),
);
}
public function get_form_editor_field_settings() {
return array(
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'admin_label_setting',
'rules_setting',
'duplicate_setting',
'description_setting',
'css_class_setting',
);
}
public function is_conditional_logic_supported() {
return true;
}
public function get_field_input( $form, $value = '', $entry = null ) {
$is_entry_detail = $this->is_entry_detail();
$is_form_editor = $this->is_form_editor();
$form_id = $form['id'];
$field_id = intval( $this->id );
$first = $last = $email = $phone = '';
if ( is_array( $value ) ) {
$first = esc_attr( rgget( $this->id . '.1', $value ) );
$last = esc_attr( rgget( $this->id . '.2', $value ) );
$email = esc_attr( rgget( $this->id . '.3', $value ) );
$phone = esc_attr( rgget( $this->id . '.4', $value ) );
}
$disabled_text = $is_form_editor ? "disabled='disabled'" : '';
$class_suffix = $is_entry_detail ? '_admin' : '';
$first_tabindex = GFCommon::get_tabindex();
$last_tabindex = GFCommon::get_tabindex();
$email_tabindex = GFCommon::get_tabindex();
$phone_tabindex = GFCommon::get_tabindex();
$required_attribute = $this->isRequired ? 'aria-required="true"' : '';
$invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
$first_markup = '<span id="input_' . $field_id . '_' . $form_id . '.1_container" class="attendees_first">';
$first_markup .= '<input type="text" name="input_' . $field_id . '.1" id="input_' . $field_id . '_' . $form_id . '_1" value="' . $first . '" aria-label="First Name" ' . $first_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$first_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_1">First Name</label>';
$first_markup .= '</span>';
$last_markup = '<span id="input_' . $field_id . '_' . $form_id . '.2_container" class="attendees_last">';
$last_markup .= '<input type="text" name="input_' . $field_id . '.2" id="input_' . $field_id . '_' . $form_id . '_2" value="' . $last . '" aria-label="Last Name" ' . $last_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$last_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_2">Last Name</label>';
$last_markup .= '</span>';
$email_markup = '<span id="input_' . $field_id . '_' . $form_id . '.3_container" class="attendees_email">';
$email_markup .= '<input type="text" name="input_' . $field_id . '.3" id="input_' . $field_id . '_' . $form_id . '_3" value="' . $email . '" aria-label="Email" ' . $email_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$email_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_3">Email</label>';
$email_markup .= '</span>';
$phone_markup = '<span id="input_' . $field_id . '_' . $form_id . '.4_container" class="attendees_phone">';
$phone_markup .= '<input type="text" name="input_' . $field_id . '.4" id="input_' . $field_id . '_' . $form_id . '_4" value="' . $phone . '" aria-label="Phone #" ' . $phone_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$phone_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_4">Phone #</label>';
$phone_markup .= '</span>';
$css_class = $this->get_css_class();
return "<div class='ginput_complex{$class_suffix} ginput_container {$css_class} gfield_trigger_change' id='{$field_id}'>
{$first_markup}
{$last_markup}
{$email_markup}
{$phone_markup}
<div class='gf_clear gf_clear_complex'></div>
</div>";
}
public function get_css_class() {
$first_input = GFFormsModel::get_input( $this, $this->id . '.1' );
$last_input = GFFormsModel::get_input( $this, $this->id . '.2' );
$email_input = GFFormsModel::get_input( $this, $this->id . '.3' );
$phone_input = GFFormsModel::get_input( $this, $this->id . '.4' );
$css_class = '';
$visible_input_count = 0;
if ( $first_input && ! rgar( $first_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_first_name ';
} else {
$css_class .= 'no_first_name ';
}
if ( $last_input && ! rgar( $last_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_last_name ';
} else {
$css_class .= 'no_last_name ';
}
if ( $email_input && ! rgar( $email_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_email ';
} else {
$css_class .= 'no_email ';
}
if ( $phone_input && ! rgar( $phone_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_phone ';
} else {
$css_class .= 'no_phone ';
}
$css_class .= "gf_attendees_has_{$visible_input_count} ginput_container_attendees ";
return trim( $css_class );
}
public function get_form_editor_inline_script_on_page_render() {
// set the default field label for the field
$script = sprintf( "function SetDefaultValues_%s(field) {
field.label = '%s';
field.inputs = [new Input(field.id + '.1', '%s'), new Input(field.id + '.2', '%s'), new Input(field.id + '.3', '%s'), new Input(field.id + '.4', '%s')];
}", $this->type, $this->get_form_editor_field_title(), 'First Name', 'Last Name', 'Email', 'Phone' ) . PHP_EOL;
return $script;
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
if ( is_array( $value ) ) {
$first = trim( rgget( $this->id . '.1', $value ) );
$last = trim( rgget( $this->id . '.2', $value ) );
$email = trim( rgget( $this->id . '.3', $value ) );
$phone = trim( rgget( $this->id . '.4', $value ) );
$return = $first;
$return .= ! empty( $return ) && ! empty( $last ) ? " $last" : $last;
$return .= ! empty( $return ) && ! empty( $email ) ? " $email" : $email;
$return .= ! empty( $return ) && ! empty( $phone ) ? " $phone" : $phone;
} else {
$return = '';
}
if ( $format === 'html' ) {
$return = esc_html( $return );
}
return $return;
}
}
GF_Fields::register( new GF_Field_Attendees() );
I've been having difficulties getting the value from rgget for the fields and I had to change it to the following to get it to work:
rgget( 'input_' . $this->id . '_1', $value )
Related
First of all, sorry for my lack of knowledge in PHP. I have tried googling for the answer, and also tried several answers here. For some reason passing argument in my function isn't working. However, if I directly call the default value in function, it works. Here is the function I am using.
function pnet_breadcrumbs( $seperator = '»', $home = true, $blog = true, $show_hierarchy = true ) {
global $post, $wp_query;
$html = '<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">';
$position = 1;
if ( $home ) {
$html .= '<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to ' . get_option( 'blogname' ) . '." href="' . home_url( '/' ) . '" class="home"><span property="name">' . get_option( 'blogname' ) . '</span></a><meta property="position" content="' . $position . '"></span>' . $seperator;
$html .= ' ' . $seperator . ' '; //Not Working
$html .= ' » '; //Working
$position = $position + 1;
}
if ( is_tax() || is_category() || is_tag() ) {
$obj = $wp_query->get_queried_object();
if ( $show_hierarchy ) {
$ancestors = get_ancestors( $obj->term_id, $obj->taxonomy, 'taxonomy' );
if ( is_array($ancestors) && !empty($ancestors) ) {
$ancestors = array_reverse( $ancestors );
foreach( $ancestors as $ancestor ) {
$term_obj = get_term($ancestor);
$term_url = get_term_link($term_obj->term_id);
$html .= '<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="' . sprintf( __( 'View Archive for %s.', 'pnet' ), $term_obj->name ) . '." href="' . $term_url . '" class="home"><span property="name">' . $term_obj->name . '</span></a><meta property="position" content="' . $position . '"></span>';
$html .= $seperator;
$position++;
}
}
}
$html .= '<span property="itemListElement" typeof="ListItem"><span property="name">' . $obj->name . '</span><meta property="position" content="' . $position . '"></span>';
}
if ( is_search() ) {
$html .= '<span property="itemListElement" typeof="ListItem"><span property="name">' . sprintf( __( 'Search results for %s.', 'pnet' ), get_search_query() ) . '</span><meta property="position" content="' . $position . '"></span>';
}
$html .= '</div>';
echo $html;
}
add_action( 'wp_footer', 'pnet_breadcrumbs', 0 );
The variable $seperator is returning empty.
I know this is basic PHP, but I really can't figure out why I can't use a default value. What am I doing wrong?
I am trying to add functionality to allow a customer to edit options.
I have created a Module Vendor/COptions.
This is loading custom options and select, however is not getting user selected options.
I would like to know how to received selected options and check if the option is selected.
At the moment this line in Select.php is not receiving anything, and the variable $checked is null.
$configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $_option->getId());
in Vendor/COptions\view\frontend\templates\cart\item\default.phtml :
<?php $selectedOptions = $block->getSelectedOptionList(); ?>
<?php //$_options = Mage::helper('core')->decorateArray($block>getOptions())
$_options = $block->getOptions() ?>
<?php if ($_options AND count($_options)):?>
<dl>
<?php foreach($_options as $_option): ?>
<?php echo $this->getOptionHtml($_option) ?>
<?php endforeach; ?>
</dl>
<?php endif; ?>
in Vendor\COptions\Helper\Rewrite\Product:
public function getCustomOptions(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item, $simple="")
{
$product = $item->getProduct();
$coptions = [];
$coptions = $product->getOptions();
$options = array();
if ($coptions) {
foreach ($coptions as $option) {
$itemOption = $item->getOptionByCode('option_' . $option->getId());
/** #var $group \Magento\Catalog\Model\Product\Option\Type\DefaultType */
$group = $option->groupFactory($option->getType())
->setOption($option)
->setConfigurationItem($item)
->setConfigurationItemOption($itemOption);
if ('file' == $option->getType()) {
$downloadParams = $item->getFileDownloadParams();
if ($downloadParams) {
$url = $downloadParams->getUrl();
if ($url) {
$group->setCustomOptionDownloadUrl($url);
}
$urlParams = $downloadParams->getUrlParams();
if ($urlParams) {
$group->setCustomOptionUrlParams($urlParams);
}
}
}
if($simple == "Y"){
array_push($options, $itemOption['value']);
}else{
$options[] = [
'label' => $option->getTitle(),
'value' => $group->getFormattedOptionValue($itemOption['value']),
'print_value' => $group->getFormattedOptionValue($itemOption['value']),
'option_id' => $option->getId(),
'option_type' => $option->getType(),
'custom_view' => $group->isCustomizedView(),
];
}
}
}
$addOptions = $item->getOptionByCode('additional_options');
if ($addOptions) {
$options = array_merge($options, $this->serializer->unserialize($addOptions->getValue()));
}
return $options;
}
in Vendor/COptions\Block\Rewrite\Catalog\Product\View\Options\Type\Select.php:
public function getValuesHtml()
{
$_option = $this->getOption();
$configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $_option->getId());
$store = $this->getProduct()->getStore();
$this->setSkipJsReloadPrice(1);
// Remove inline prototype onclick and onchange events
if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN ||
$_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_MULTIPLE
) {
$require = $_option->getIsRequire() ? ' required' : '';
$extraParams = '';
$select = $this->getLayout()->createBlock(
\Magento\Framework\View\Element\Html\Select::class
)->setData(
[
'id' => 'select_' . $_option->getId(),
'class' => $require . ' product-custom-option admin__control-select'
]
);
if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN) {
$select->setName('options[' . $_option->getid() . ']')->addOption('', __('-- Please Select --'));
} else {
$select->setName('options[' . $_option->getid() . '][]');
$select->setClass('multiselect admin__control-multiselect' . $require . ' product-custom-option');
}
foreach ($_option->getValues() as $_value) {
$priceStr = $this->_formatPrice(
[
'is_percent' => $_value->getPriceType() == 'percent',
'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent'),
],
false
);
$select->addOption(
$_value->getOptionTypeId(),
$_value->getTitle() . ' ' . strip_tags($priceStr) . '',
['price' => $this->pricingHelper->currencyByStore($_value->getPrice(true), $store, false)]
);
}
if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_MULTIPLE) {
$extraParams = ' multiple="multiple"';
}
if (!$this->getSkipJsReloadPrice()) {
$extraParams .= ' onchange="opConfig.reloadPrice()"';
}
$extraParams .= ' data-selector="' . $select->getName() . '"';
$select->setExtraParams($extraParams);
if ($configValue) {
$select->setValue($configValue);
}
return $select->getHtml();
}
if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO ||
$_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX
) {
$selectHtml = '<div class="options-list nested" id="options-' . $_option->getId() . '-list">';
$require = $_option->getIsRequire() ? ' required' : '';
$arraySign = '';
switch ($_option->getType()) {
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO:
$type = 'radio';
$class = 'radio admin__control-radio';
if (!$_option->getIsRequire()) {
$selectHtml .= '<div class="field choice admin__field admin__field-option">' .
'<input type="radio" id="options_' .
$_option->getId() .
'" class="' .
$class .
' product-custom-option" name="options[' .
$_option->getId() .
']"' .
' data-selector="options[' . $_option->getId() . ']"' .
($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') .
' value="" checked="checked" /><label class="label admin__field-label" for="options_' .
$_option->getId() .
'"><span>' .
__('None') . '</span></label></div>';
}
break;
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX:
$type = 'checkbox';
$class = 'checkbox admin__control-checkbox';
$arraySign = '[]';
break;
}
$count = 1;
foreach ($_option->getValues() as $_value) {
$count++;
$priceStr = $this->_formatPrice(
[
'is_percent' => $_value->getPriceType() == 'percent',
'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent'),
]
);
$htmlValue = $_value->getOptionTypeId();
if ($arraySign) {
$checked = is_array($configValue) && in_array($htmlValue, $configValue) ? 'checked' : '';
} else {
$checked = $configValue == $htmlValue ? 'checked' : '';
}
$dataSelector = 'options[' . $_option->getId() . ']';
if ($arraySign) {
$dataSelector .= '[' . $htmlValue . ']';
}
$selectHtml .= '<div class="field choice admin__field admin__field-option' .
$require .
'">' .
'<input type="' .
$type .
'" class="' .
$class .
' ' .
$require .
' product-custom-option"' .
($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') .
' name="options[' .
$_option->getId() .
']' .
$arraySign .
'" id="options_' .
$_option->getId() .
'_' .
$count .
'" value="' .
$htmlValue .
'" ' .
$checked .
' data-selector="' . $dataSelector . '"' .
' price="' .
$this->pricingHelper->currencyByStore($_value->getPrice(true), $store, false) .
'" />' .
'<label class="label admin__field-label" for="options_' .
$_option->getId() .
'_' .
$count .
'"><span>' .
$_value->getTitle() .
'</span> ' .
$priceStr .
'</label>';
$selectHtml .= '</div>';
}
$selectHtml .= '</div>';
return $selectHtml;
}
}
I am using top 10 -popular post plugin.
I added the following lines but it wont display...
$output .= '<li>' .wpautop(wp_trim_words($result["post_content"], 15)). '</li>';
code:
function tptn_pop_posts( $args ) {
global $wpdb, $siteurl, $tableposts, $id, $tptn_settings;
$defaults = array(
'is_widget' => FALSE,
'daily' => FALSE,
'echo' => FALSE,
'strict_limit' => FALSE,
'posts_only' => FALSE,
'is_shortcode' => FALSE,
'heading' => 1,
);
$defaults = array_merge( $defaults, $tptn_settings );
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
// OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
extract( $args, EXTR_SKIP );
if ($daily) {
$table_name = $wpdb->prefix . "top_ten_daily";
} else {
$table_name = $wpdb->prefix . "top_ten";
}
$limit = ( $strict_limit ) ? $limit : ( $limit * 5 );
$exclude_categories = explode( ',', $exclude_categories );
$target_attribute = ( $link_new_window ) ? ' target="_blank" ' : ' '; // Set Target attribute
$rel_attribute = ( $link_nofollow ) ? ' nofollow' : ''; // Set nofollow attribute
parse_str( $post_types, $post_types ); // Save post types in $post_types variable
if ( ! $daily ) {
$args = array();
$sql = "SELECT postnumber, cntaccess as sumCount, ID, post_type, post_status ";
$sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
$sql .= "AND post_status = 'publish' ";
if ( '' != $exclude_post_ids ) {
$sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
}
$sql .= "AND ( ";
$multiple = false;
foreach ( $post_types as $post_type ) {
if ( $multiple ) $sql .= ' OR ';
$sql .= " post_type = '%s' ";
$multiple = true;
$args[] = $post_type; // Add the post types to the $args array
}
$sql .= " ) ";
$sql .= "ORDER BY sumCount DESC LIMIT %d";
$args[] = $limit;
} else {
$current_time = current_time( 'timestamp', 0 );
$current_time = $current_time - ( $daily_range - 1 ) * 3600 * 24;
$current_date = date( 'Y-m-j', $current_time );
$args = array(
$current_date,
);
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
$sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
$sql .= "AND post_status = 'publish' AND dp_date >= '%s' ";
if ( '' != $exclude_post_ids ) {
$sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
}
$sql .= "AND ( ";
$multiple = false;
foreach ( $post_types as $post_type ) {
if ( $multiple ) $sql .= ' OR ';
$sql .= " post_type = '%s' ";
$multiple = true;
$args[] = $post_type; // Add the post types to the $args array
}
$sql .= " ) ";
$sql .= "GROUP BY postnumber ";
$sql .= "ORDER BY sumCount DESC LIMIT %d";
$args[] = $limit;
}
if ( $posts_only ) { // Return the array of posts only if the variable is set
return apply_filters( 'tptn_pop_posts_array', $wpdb->get_results( $wpdb->prepare( $sql , $args ) , ARRAY_A ) );
}
$results = $wpdb->get_results( $wpdb->prepare( $sql , $args ) );
$counter = 0;
$output = '';
$shortcode_class = $is_shortcode ? ' tptn_posts_shortcode' : '';
$widget_class = $is_widget ? ' tptn_posts_widget' : '';
if ( $heading ) {
if ( ! $daily ) {
$output .= '<div id="tptn_related" class="tptn_posts ' . $widget_class . $shortcode_class . '">' . apply_filters( 'tptn_heading_title', $title );
} else {
$output .= '<div id="tptn_related_daily" class="tptn_posts_daily' . $shortcode_class . '">' . apply_filters( 'tptn_heading_title', $title_daily );
}
} else {
if ( ! $daily ) {
$output .= '<div class="tptn_posts' . $widget_class . $shortcode_class . '">';
} else {
$output .= '<div class="tptn_posts_daily' . $widget_class . $shortcode_class . '">';
}
}
if ( $results ) {
$output .= apply_filters( 'tptn_before_list', $before_list );
foreach ( $results as $result ) {
$sumcount = $result->sumCount;
$result = get_post( apply_filters( 'tptn_post_id', $result->ID ) ); // Let's get the Post using the ID
$categorys = get_the_category( apply_filters( 'tptn_post_cat_id', $result->ID ) ); //Fetch categories of the plugin
$p_in_c = false; // Variable to check if post exists in a particular category
foreach ( $categorys as $cat ) { // Loop to check if post exists in excluded category
$p_in_c = ( in_array( $cat->cat_ID, $exclude_categories ) ) ? true : false;
if ( $p_in_c ) break; // End loop if post found in category
}
$title = tptn_max_formatted_content( get_the_title( $result->ID ), $title_length );
if ( ! $p_in_c ) {
$output .= apply_filters( 'tptn_before_list_item', $before_list_item, $result->ID );
if ( 'after' == $post_thumb_op ) {
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
$output .= '<span class="tptn_title">' . $title . '</span>'; // Add title if post thumbnail is to be displayed after
$output .= '</a>'; // Close the link
}
if ( 'inline' == $post_thumb_op || 'after' == $post_thumb_op || 'thumbs_only' == $post_thumb_op ) {
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
$output .= tptn_get_the_post_thumbnail( array(
'postid' => $result->ID,
'thumb_height' => $thumb_height,
'thumb_width' => $thumb_width,
'thumb_meta' => $thumb_meta,
'thumb_html' => $thumb_html,
'thumb_default' => $thumb_default,
'thumb_default_show' => $thumb_default_show,
'thumb_timthumb' => $thumb_timthumb,
'thumb_timthumb_q' => $thumb_timthumb_q,
'scan_images' => $scan_images,
'class' => "tptn_thumb",
'filter' => "tptn_postimage",
) );
$output .= '</a>'; // Close the link
}
if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
$output .= '<span class="tptn_after_thumb">';
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
$output .= '<span class="tptn_title">' . $title . '</span>'; // Add title when required by settings
// $output .= '<li>' .wpautop(wp_trim_words($result["post_content"], 15)). '</li>';
$output .= '</a>'; // Close the link
}
if ( $show_author ) {
$author_info = get_userdata( $result->post_author );
$author_name = ucwords( trim( stripslashes( $author_info->display_name ) ) );
$author_link = get_author_posts_url( $author_info->ID );
$output .= '<span class="tptn_author"> ' . __( ' by ', TPTN_LOCAL_NAME ).'' . $author_name . '</span> ';
}
if ( $show_date ) {
$output .= '<span class="tptn_date"> ' . mysql2date( get_option( 'date_format', 'd/m/y' ), $result->post_date ).'</span> ';
}
if ( $show_excerpt ) {
$output .= '<span class="tptn_excerpt"> ' . tptn_excerpt( $result->ID, $excerpt_length ).'</span>';
}
if ( $disp_list_count ) $output .= ' <span class="tptn_list_count">(' . number_format_i18n( $sumcount ) . ')</span>';
if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
$output .= '</span>';
}
$output .= apply_filters( 'tptn_after_list_item', $after_list_item, $result->ID );
$counter++;
}
if ( $counter == $limit/5 ) break; // End loop when related posts limit is reached
}
if ( $show_credit ) {
$output .= apply_filters( 'tptn_before_list_item', $before_list_item, $result->ID );
$output .= sprintf( 'Popular posts by Top 10 plugin', TPTN_LOCAL_NAME );
$output .= apply_filters( 'tptn_after_list_item', $after_list_item, $result->ID );
}
$output .= apply_filters( 'tptn_after_list', $after_list );
} else {
$output .= ( $blank_output ) ? '' : $blank_output_text;
}
$output .= '</div>';
return apply_filters( 'tptn_pop_posts', $output );
}
You seem to be returning $output. You will need to use echo in order for your HTML to display.
Ref: http://php.net/manual/en/function.echo.php
to show content in popular post by adding the following line below the code.
$output .= '<li><p>' .wp_trim_words(get_post($result->ID)->post_content,15). '</p></li>';
top10.php (top10 popular post plugin)
code:
if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
$output .= '<span class="tptn_after_thumb">';
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
$output .= '<span class="tptn_title">' . $title . '</span>'; // Add title when required by settings
$output .= '</a>'; // Close the link
$output .= '<li><p>' .wp_trim_words(get_post($result->ID)->post_content,15). '</p></li>';
}
In WooCommerce > Settings > Products, I have set "Shop Page Display" to "Show subcategories" - so that on my main shop page (http://example.com/shop/) only categories (and no individual products) are shown.
I have also used this code snippet to make the product categories show in my breadcrumbs as my theme uses WooTheme's "Simplicity" theme as its parent.
The problem I have is that the breadcrumbs are not displaying correctly. The breadcrumbs look fine on the shop home page...
You are here: Home > Products
But when I then click on a category from that page, the breadcrumbs change to...
You are here: Home > Chocolate
...when it should really be...
You are here: Home > Products > Chocolate
To confirm the issue, when I then click on a product, the breadcrumbs look fine again...
You are here: Home > Products > Chocolate > Vegan Chocolate bar
Does anyone know how I can fix the problematic breadcrumbs on the categories page?
As this seems like a bug, I have asked WooCommerce for their support, but they're not willing to fix it.
Thanks in advance.
Add this to your funtions.php file
// Breadcrumbs Display Category Name
// ====================================================================
function get_breadcrumb_category( $cat ) {
$post = get_post( $post->ID );
$post_type = $post->post_type;
$taxonomy = $cat;
$f_categories = wp_get_post_terms( $post->ID, $taxonomy );
$f_category = $f_categories[0];
if ( $f_category->parent != 0 ) {
$f_category_id = $f_category->parent;
$parent_array = get_term_by('id', $f_category_id, $taxonomy, 'ARRAY_A');
$f_category_name = $parent_array["name"];
$term_link = get_term_link( $f_category_id, $taxonomy );
} else {
$f_category_id = $f_category->term_id;
$f_category_name = $f_category->name;
$term_link = get_term_link( $f_category_id, $taxonomy );
}
if ( $f_categories && ! is_wp_error($f_categories) ) {
return '' . $f_category_name . '';
} else {
return '';
}
}
function x_breadcrumbs() {
if ( x_get_option( 'x_breadcrumb_display', '1' ) ) {
GLOBAL $post;
$is_ltr = ! is_rtl();
$stack = x_get_stack();
$delimiter = x_get_breadcrumb_delimiter();
$home_text = x_get_breadcrumb_home_text();
$home_link = home_url();
$current_before = x_get_breadcrumb_current_before();
$current_after = x_get_breadcrumb_current_after();
$page_title = get_the_title();
$blog_title = get_the_title( get_option( 'page_for_posts', true ) );
$post_parent = $post->post_parent;
if ( X_WOOCOMMERCE_IS_ACTIVE ) {
$shop_url = x_get_shop_link();
$shop_title = x_get_option( 'x_' . $stack . '_shop_title', __( 'The Shop', '__x__' ) );
$shop_link = '' . $shop_title . '';
}
echo '<div class="x-breadcrumbs">' . $home_text . '' . $delimiter;
if ( is_home() ) {
echo $current_before . $blog_title . $current_after;
} elseif ( is_category() ) {
$the_cat = get_category( get_query_var( 'cat' ), false );
if ( $the_cat->parent != 0 ) echo ''.get_the_title(102) .'';
echo $current_before . single_cat_title( '', false ) . $current_after;
} elseif ( x_is_product_category() ) {
if ( $is_ltr ) {
echo $shop_link . $delimiter . $current_before . single_cat_title( '', false ) . $current_after;
} else {
echo $current_before . single_cat_title( '', false ) . $current_after . $delimiter . $shop_link;
}
} elseif ( x_is_product_tag() ) {
if ( $is_ltr ) {
echo $shop_link . $delimiter . $current_before . single_tag_title( '', false ) . $current_after;
} else {
echo $current_before . single_tag_title( '', false ) . $current_after . $delimiter . $shop_link;
}
} elseif ( is_search() ) {
echo $current_before . __( 'Search Results for ', '__x__' ) . '“' . get_search_query() . '”' . $current_after;
} elseif ( is_singular( 'post' ) ) {
if ( get_option( 'page_for_posts' ) == is_front_page() ) {
echo $current_before . $page_title . $current_after;
} else {
if ( $is_ltr ) {
$f_category = get_the_category();
if ( $f_category[0]->parent != 0 ) {
$f_category_id = $f_category[0]->parent;
$f_category_name = get_cat_name( $f_category_id );
} else {
$f_category_id = $f_category[0]->term_id;
$f_category_name = $f_category[0]->name;
}
echo '' . $f_category_name . '' . $delimiter . $current_before . $page_title . $current_after;
} else {
echo $current_before . $page_title . $current_after . $delimiter . '' . $blog_title . '';
}
}
} elseif ( x_is_portfolio() ) {
echo $current_before . get_the_title() . $current_after;
} elseif ( x_is_portfolio_item() ) {
$link = x_get_parent_portfolio_link();
$title = x_get_parent_portfolio_title();
if ( $v = get_breadcrumb_category('portfolio-category') ) {
$portfolio_category = $delimiter . $v;
} else {
$portfolio_category = '';
}
if ( $is_ltr ) {
echo '' . $title . '' . $portfolio_category . $delimiter . $current_before . $page_title . $current_after;
} else {
echo $current_before . $page_title . $current_after . $portfolio_category . $delimiter . '' . $title . '';
}
} elseif ( x_is_product() ) {
if ( $v = get_breadcrumb_category('product_cat') ) {
$product_category = $delimiter . $v;
} else {
$product_category = '';
}
if ( $is_ltr ) {
echo $shop_link . $product_category . $delimiter . $current_before . $page_title . $current_after;
} else {
echo $current_before . $page_title . $current_after . $product_category . $delimiter . $shop_link;
}
} elseif ( x_is_buddypress() ) {
if ( bp_is_group() ) {
echo '' . x_get_option( 'x_buddypress_groups_title', __( 'Groups', '__x__' ) ) . '' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
} elseif ( bp_is_user() ) {
echo '' . x_get_option( 'x_buddypress_members_title', __( 'Members', '__x__' ) ) . '' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
} else {
echo $current_before . x_buddypress_get_the_title() . $current_after;
}
} elseif ( x_is_bbpress() ) {
remove_filter( 'bbp_no_breadcrumb', '__return_true' );
if ( bbp_is_forum_archive() ) {
echo $current_before . bbp_get_forum_archive_title() . $current_after;
} else {
echo bbp_get_breadcrumb();
}
add_filter( 'bbp_no_breadcrumb', '__return_true' );
} elseif ( is_page() && ! $post_parent ) {
echo $current_before . $page_title . $current_after;
} elseif ( is_page() && $post_parent ) {
$parent_id = $post_parent;
$breadcrumbs = array();
if ( is_rtl() ) {
echo $current_before . $page_title . $current_after . $delimiter;
}
while ( $parent_id ) {
$page = get_page( $parent_id );
$breadcrumbs[] = '' . get_the_title( $page->ID ) . '';
$parent_id = $page->post_parent;
}
if ( $is_ltr ) {
$breadcrumbs = array_reverse( $breadcrumbs );
}
for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
echo $breadcrumbs[$i];
if ( $i != count( $breadcrumbs ) -1 ) echo $delimiter;
}
if ( $is_ltr ) {
echo $delimiter . $current_before . $page_title . $current_after;
}
} elseif ( is_tag() ) {
echo $current_before . single_tag_title( '', false ) . $current_after;
} elseif ( is_author() ) {
GLOBAL $author;
$userdata = get_userdata( $author );
echo $current_before . __( 'Posts by ', '__x__' ) . '“' . $userdata->display_name . $current_after . '”';
} elseif ( is_404() ) {
echo $current_before . __( '404 (Page Not Found)', '__x__' ) . $current_after;
} elseif ( is_archive() ) {
if ( x_is_shop() ) {
echo $current_before . $shop_title . $current_after;
} else {
echo $current_before . __( 'Archives ', '__x__' ) . $current_after;
}
}
echo '</div>';
}
}
starting from the } elseif ( x_is_product() ) { and finishing at the } elseif ( x_is_buddypress() ) {
} elseif ( x_is_product() ) {
$product_categories = wp_get_post_terms( get_the_ID(), 'product_cat' );
$parent = '';
$sub_category = '';
foreach ($product_categories as $category ) {
$term_id = $category->term_id;
$term_name = get_term( $term_id, 'product_cat' );
if ( $category->parent != 0 ) {
$sub_category .= $parent_id . '' . $term_name->name . '' . $delimiter ;
} else {
$parent .= '' . $term_name->name . '' . $delimiter ;
}
}
if ( $v = get_breadcrumb_category('product_cat') ) {
$product_category = $delimiter . $v;
} else {
$product_category = '';
}
if ( $is_ltr ) {
if(is_array($product_categories)){
echo $shop_link . $product_category . $delimiter . $sub_category . $current_before . $page_title . $current_after;
}
else {
echo $shop_link . $delimiter . $current_before . $page_title . $current_after;
}
} else {
echo $current_before . $page_title . $current_after . $delimiter . $shop_link;
}
} elseif ( x_is_buddypress() ) {
I have a php script which creates its own button, as I am using an open source framework. What I want is to use an image to create a button instead of a the link the is created. Here is the line for which I need the button:
<td class="main button_marg"><?php echo tep_draw_button(IMAGE_BUTTON_REVIEWS . (($reviews['count'] > 0) ? ' (' . $reviews['count'] . ')' : ''), 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params())); ?></td>
That is the script I am using to create the review button, but I would like to insert an image into it. Any ideas would be most appreciative.
This is the code for tep_draw_button() function:
function tep_draw_button($title = null, $icon = null, $link = null, $priority = null, $params = null) {
static $button_counter = 1;
$types = array('submit', 'button', 'reset');
if ( !isset($params['type']) ) {
$params['type'] = 'submit';
}
if ( !in_array($params['type'], $types) ) {
$params['type'] = 'submit';
}
if ( ($params['type'] == 'submit') && isset($link) ) {
$params['type'] = 'button';
}
if (!isset($priority)) {
$priority = 'secondary';
}
$button = '<span class="tdbLink">';
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
if ( isset($params['newwindow']) ) {
$button .= ' target="_blank"';
}
} else {
$button .= '<button id="tdb' . $button_counter . '" type="' . tep_output_string($params['type']) . '"';
}
if ( isset($params['params']) ) {
$button .= ' ' . $params['params'];
}
$button .= '>' . $title;
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '</a>';
} else {
$button .= '</button>';
}
$button .= '</span><script type="text/javascript">$("#tdb' . $button_counter . '").button(';
$args = array();
if ( isset($icon) ) {
if ( !isset($params['iconpos']) ) {
$params['iconpos'] = 'left';
}
if ( $params['iconpos'] == 'left' ) {
$args[] = 'icons:{primary:"ui-icon-' . $icon . '"}';
} else {
$args[] = 'icons:{secondary:"ui-icon-' . $icon . '"}';
}
}
if (empty($title)) {
$args[] = 'text:false';
}
if (!empty($args)) {
$button .= '{' . implode(',', $args) . '}';
}
$button .= ').addClass("ui-priority-' . $priority . '").parent().removeClass("tdbLink");</script>';
$button_counter++;
return $button;
}
?>
You can probably override the style by using some css:
#your_button_id{ background: url(); height: x; width: x; etc... }
.your_button_class{ background: url(); height: x; width: x; etc... }
Try this:
To call the button, use the function with the parameters as they are below:
$image['src'] = 'http://yoururl.com/image.jpg'; // Image Source
$image['height'] = 600; // Image Height
$image['width'] = 300; // Image Width
tep_draw_button(IMAGE_BUTTON_REVIEWS . (($reviews['count'] > 0) ? ' (' . $reviews['count'] . ')' : ''), 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params()), null, null, $image);
Then modify the tep_draw_button function like so. If you have an image source in the function parameter, the image will be placed in as a link rather than as a button.
<?
function tep_draw_button($title = null, $icon = null, $link = null, $priority = null, $params = null, $image = null) {
static $button_counter = 1;
if($image != null){
$button = '<span class="tdbLink">';
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
$button .= '><img src="'. $image['src'] .'"';
if(is_numeric($image['height'])) $button .= ' height="'.$image['height'].'"';
if(is_numeric($image['width'])) $button .= ' width="'.$image['width'].'"';
$button .= 'alt="'.$title.'" /></a></span>';
}else{
$types = array('submit', 'button', 'reset');
if ( !isset($params['type']) ) {
$params['type'] = 'submit';
}
if ( !in_array($params['type'], $types) ) {
$params['type'] = 'submit';
}
if ( ($params['type'] == 'submit') && isset($link) ) {
$params['type'] = 'button';
}
if (!isset($priority)) {
$priority = 'secondary';
}
$button = '<span class="tdbLink">';
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
if ( isset($params['newwindow']) ) {
$button .= ' target="_blank"';
}
} else {
$button .= '<button id="tdb' . $button_counter . '" type="' . tep_output_string($params['type']) . '"';
}
if ( isset($params['params']) ) {
$button .= ' ' . $params['params'];
}
$button .= '>' . $title;
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '</a>';
} else {
$button .= '</button>';
}
$button .= '</span><script type="text/javascript">$("#tdb' . $button_counter . '").button(';
$args = array();
if ( isset($icon) ) {
if ( !isset($params['iconpos']) ) {
$params['iconpos'] = 'left';
}
if ( $params['iconpos'] == 'left' ) {
$args[] = 'icons:{primary:"ui-icon-' . $icon . '"}';
} else {
$args[] = 'icons:{secondary:"ui-icon-' . $icon . '"}';
}
}
if (empty($title)) {
$args[] = 'text:false';
}
if (!empty($args)) {
$button .= '{' . implode(',', $args) . '}';
}
$button .= ').addClass("ui-priority-' . $priority . '").parent().removeClass("tdbLink");</script>';
$button_counter++;
}
return $button;
}
?>
Let me know if this works, or if you need it tweaked at all. It's hard for me to test since I don't have an oscommerce instance on my machine to test on.