This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I got this error from my product.tpl, inserted some codes to manipulate my price and stocks, im looking to end my code using this } absolutely but i got no luck.
<?php if($price == "₱0.00" && $stock == "In Stock" ) { ?><?php echo "Customizable"; ?>
<?php } else { ?>
<?php if($price == "₱0.00" && $stock == "For inquiry") { ?><?php echo "For inquiry"; ?>
<?php } else { ?>
<?php if($price) { ?><?php echo $price; ?></h4>
<?php } ?>
Originally the code is this and i added to a little bit of code to the highlighted code
<ul class="list-unstyled">
<?php if (!$special) { ?>
<li>
<h4><?php if($price) { ?><?php echo $price; ?></h4>
</li>
<?php } else { ?>
<li><span style="text-decoration: line-through;"><?php echo $price; ?>
</span>
<h4><?php echo $special; ?></h4></li>
<?php } ?>
<?php if ($tax) { ?>
<li><?php echo $text_tax; ?><?php echo $tax; ?></li>
<?php } ?>
<?php if ($points) { ?>
<li><?php echo $text_points; ?> <?php echo $points; ?></li>
<?php } ?>
<?php if ($discounts) { ?>
<?php foreach ($discounts as $discount) { ?>
<li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?>
<?php echo $discount['price']; ?></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
Formatting your code properly really helps. Does the code below work the way you want it to?
<?php if(!$special) { ?>
<ul class="list-unstyled">
<li>
<?php if($price == "₱0.00" && $stock == "In Stock" ) {
echo "Customizable";
} else if($price == "₱0.00" && $stock == "For inquiry") {
echo "For inquiry";
} else if($price) { ?>
<h4><?=$price;?></h4>
<?php } else { ?>
<span style="text-decoration: line-through;"><?=$price;?></span>
<h4><?=$special;?></h4>
<?php } ?>
</li>
<?php if($tax) { ?>
<li><?=$text_tax.' '.$tax;?></li>
<?php } ?>
<?php if($points) { ?>
<li><?=$text_points.' '.$points;?></li>
<?php } ?>
<?php if(count($discounts)) { foreach ($discounts as $discount) { ?>
<li><?=$discount['quantity'].' '.$text_discount.' '.$discount['price'];?></li>
<?php } } ?>
</ul>
<?php } ?>
Use proper format, too many tags of php, use codes look like this.
<?php
if($price == "₱0.00" && $stock == "In Stock" ) {
echo "Customizable";
} else if($price == "₱0.00" && $stock == "For inquiry") {
echo "For inquiry";
} else if($price) {
echo $price;
}
?>
The if elseif is used like below:
<?php if($condition) { //action } elseif($condition2) { //action2 } ?>
I think you want this:
<ul class="list-unstyled">
<?php if(!$special) { ?>
<li>
<h4><?php echo $price; ?></h4>
</li>
<?php }else{ ?>
<li>
<span style="text-decoration: line-through;"><?php echo $price; ?></span>
<h4><?php echo $special; ?></h4>
</li>
<?php if($tax) { echo '<li>'.$text_tax.$tax.'</li>';} ?>
<?php if($points) { echo '<li>'.$text_points.$points.'</li>';} ?>
<?php
if($discounts){
foreach ($discounts as $discount) {
echo '<li>'.$discount["quantity"].$text_discount'<br>'.$discount['price'].'</li>';
}
}
?>
<?php } ?>
</ul>
Related
I've been racking my brain for weeks trying to remove this block of code, it's from paid memberships pro plugin.
I need to remove the below section as it produces the file fields on the user profile.
need to remove it and put it in a loop of its own and then print it, as I need it to be in a separate <section> from the rest of the fields that are in that original loop.
//----Trying to remove this piece of code----//
?>
<strong><?php echo $field[0]; ?></strong>
<div class="Test"><?php echo pmpromd_display_file_field($meta_field); ?></div>
<?php
//---This is the FullSnippet with the above code included----//
if(!empty($fields_array))
{
foreach($fields_array as $field)
{
if(empty($field[0]))
break;
// Fix for a trailing space in the 'fields' shortcode attribute.
if ( $field[0] === ' ' ) {
break;
}
$field_val = $field[1];
$meta_field = $pu->$field_val;
if(!empty($meta_field))
{
?>
<section class="pmpro_member_directory_<?php echo esc_attr($field[1]); ?>">
<?php
if(is_array($meta_field) && !empty($meta_field['filename']) )
{
//this is a file field
?>
<strong><?php echo $field[0]; ?></strong>
<div class="brendan"><?php echo pmpromd_display_file_field($meta_field); ?></div>
<?php
}elseif(is_array($meta_field)){
//this is a general array, check for Register Helper options first
if(!empty($rh_fields[$field[1]])) {
foreach($meta_field as $key => $value)
$meta_field[$key] = $rh_fields[$field[1]][$value];
}
?>
<strong><?php echo $field[0]; ?></strong>
<ul class="servicesList"><?php echo '<li>'.implode("</li>\n<li>",$meta_field).'</li>';?></ul>
<?php
}
elseif(!empty($rh_fields[$field[1]]) && is_array($rh_fields[$field[1]]) )
{
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo $rh_fields[$field[1]][$meta_field]; ?>
<?php
}
else
{
if($field[1] == 'user_url')
{
?>
<?php echo $field[0]; ?>
<?php
}
else
{
?>
<strong><?php echo $field[0]; ?></strong>
<?php
$meta_field_embed = wp_oembed_get($meta_field);
if(!empty($meta_field_embed)){
echo $meta_field_embed;
}else{
echo make_clickable($meta_field);
}
?>
<?php
}
}
?>
</section>
<?php
}
}
}
?>
I'm attempting to add a for loop to a php menu that will add a tertiary level to a currently existing WP menu. Unfortunately, the only editable amount of content is that posted below, so please bear with me on this one.
I'm just wondering, before I attempt to implement this code, if anyone can tell me if it will actually work, of if you assume it'll break everything.
What I've done is to take the same semantic forloop that was written for the secondary (or 'sub_nav') menu items, and repeat it in attempts to dynamically generate third level (or 'tert_nav') menu items.
<div class="main-menu-sub-navigation">
<?php
$main_nav_items = wp_get_nav_menu_items(2);
$sub_nav = array();
foreach ($main_nav_items as $item) {
if($item->menu_item_parent !== '0'){
$parent_id = $item->menu_item_parent;
$sub_nav[$parent_id][] = array('item' => $item);
}
}
$tert_nav = array();
foreach ($sub_nav_items as $item) {
if($item->menu_item_parent !== '0'){
$parent_id = $item->menu_item_parent;
$tert_nav[$parent_id][] = array('item' => $item);
}
}
?>
<div class="sub-nav-inner">
<?php foreach ($sub_nav as $key => $value) { ?>
<ul class="nav sub-nav" data-parent="<?php print $key; ?>">
<?php foreach ($value as $item) { ?>
<?php if(isset($_GET['archive'])): ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->title == 'Archives') ? 'current-menu-item' : 'menu-item'; ?>"><a href="<?php print $item['item']->url; ?>"><?php print $item['item']->title; ?>
<?php foreach ($tert_nav as $key => $value) { ?>
<ul class="nav tert-nav" data-parent="<?php print $key; ?>">
<?php foreach ($value as $item) { ?>
<?php if(isset($_GET['archive'])): ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->title == 'Archives') ? 'current-menu-item' : 'menu-item'; ?>"><?php print $item['item']->title; ?></li>
<?php else: ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->object_id == get_the_ID()) ? 'current-menu-item' : 'menu-item'; ?>"><?php print $item['item']->title; ?></li>
<?php endif; ?>
<?php } ?>
</ul>
<?php } ?>
</a></li>
<?php else: ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->object_id == get_the_ID()) ? 'current-menu-item' : 'menu-item'; ?>"><a href="<?php print $item['item']->url; ?>"><?php print $item['item']->title; ?>
<?php foreach ($sub_nav as $key => $value) { ?>
<ul class="nav tert-nav" data-parent="<?php print $key; ?>">
<?php foreach ($value as $item) { ?>
<?php if(isset($_GET['archive'])): ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->title == 'Archives') ? 'current-menu-item' : 'menu-item'; ?>"><?php print $item['item']->title; ?></li>
<?php else: ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->object_id == get_the_ID()) ? 'current-menu-item' : 'menu-item'; ?>"><?php print $item['item']->title; ?></li>
<?php endif; ?>
<?php } ?>
</ul>
<?php } ?>
</a></li>
<?php endif; ?>
<?php } ?>
</ul>
<?php } ?>
</div>
Any help would be so very greatly appreciated. Thank you!!
I keep getting syntax errors on this piece of code.
<?php
$day = get_field_object('day_of_the_week');
$value = $day['value'];
$choices = $day['choices'];
if( $value ): ?>
<ul>
<?php foreach( $value as $v ): ?>
<li>
<?php if( $v != $page_title ) { ?>
<a class="btn" href="/venture-centre/activities-2/<?php echo $choices[ $v ]; ?>#<?php echo basename(get_permalink()); ?>">
<?php echo $choices[ $v ]; ?>
</a>
<?php } ?>
</li>
<?php endforeach; ?>
</ul>
<?php } else { ?>
<p>This activity is only available on <?php echo $page_title ?>.</p>
<?php } ?>
<?php endif; ?>
You're mixing standard and alternative syntax, which is not permitted:
if( $value ): ?> // start alternative syntax block
<?php } else { ?> // where did this get opened?
You have a closing curly brace without an opening one.
See <?php } ?> after the </a>
You have to remove this line or add <?php { ?> after the for each
Thanks for all the comments, I've made the suggested changes and realise that I needed an elseif in place of the else to complete what I was trying to achieve:
<?php
$day = get_field_object('day_of_the_week');
$value = $day['value'];
$choices = $day['choices'];
if( count($value) > 1 ) { ?>
<ul>
<?php foreach( $value as $v ) { ?>
<li>
<?php if( $v != $page_title ) { ?>
<a class="btn" href="/venture-centre/activities-2/<?php echo $choices[ $v ]; ?>#<?php echo basename(get_permalink()); ?>">
<?php echo $choices[ $v ]; ?>
</a>
</li>
<?php } } } elseif( count($value) == 1 ) { ?>
<p>This activity is only available on <?php echo $page_title; ?>.</p>
<?php } ?>
on each products page I currently have displayed the products subcategory, but only one level deep. So if in categories I have Brother > MFC > B4564 > TN450.... and I am on the TN450's product page, down below it will only show BN4564 . I need it also show The mfc and the brother part. I am not sure how to do this.. any ideas? here is my current code.
.TPL file
<!-- Display product categories -->
<?php foreach ($catprod as $catp)
{
?><?php echo $catp['name']; ?> <?php
}`
controller .php file
$data['catprod'] = array();
$product_category = $this->model_catalog_product->getCategories($this->request->get['product_id']);
foreach ($product_category as $prodcat)
{
$category_info = $this->model_catalog_category->getCategory($prodcat['category_id']);
if ($category_info)
{
$data['catprod'][] = array('name' => $category_info['description'],'href' => $this->url->link('product/category', 'path=' . $category_info['category_id']));
}
}`
which version of opencart?
this should work for version 1:
open catalog/view/theme/default/template/module/category.tpl
remove its contents and insert:
<div class="box" id="categories-menu">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<ul class="box-category" id="box-category">
<?php foreach ($categories as $category) { ?>
<li>
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active list-group-item" ><?php echo $category['name']; ?></a>
<?php } else { ?>
<?php echo $category['name']; ?>
<?php } ?>
<?php if ($category['children']) { ?>
<ul class="submenu">
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
<?php $callout = array(
'1',
'3',
'5'
); ?>
<ul>
<?php foreach($callout as $call) { ?>
<li>
<h3><?php echo get_the_title($call); ?></h3>
<p>different text goes here...</p>
</li>
<?php } ?>
</ul>
Is it possible - if $call=1 then echo some static text, if 2 echo something else, and so on?
Problem solved. Thanks to #swapnesh
http://codepad.org/0mZIkJuB
<?php $callout = array(1,2,3); ?>
<ul>
<?php foreach($callout as $call) { ?>
<li>
<?php
if ('1' == $call)
echo "a";
elseif ('2' == $call)
echo "b";
elseif ('3' == $call)
echo "c";
else
echo "d";
?>
</li>
<?php } ?>
</ul>