The issue with in_array statement - php

I want to display certain URL links on a product page only for certain products and for certain countries. Initially, I retrieve the IP of the country then check, the product ID. If the product ID is in the array I display Link 1 if users are from Canada and Link 2 if they are from the US. The problem is that it is not showing anything. Nothing happens within the if statement that contains in_array and not sure what I am doing wrong.
<?php
if ($currentCountry =="CA" || $currentCountry =="US")
{
$p_id = $_product->getId();
$include_id = array(546, 125,135);
?>
<style>
.choose-local {
display: flex;
}
.data-section {
min-width: 33%;
}
.choose-local .data-section span {
float: left;
}
</style>
<?php
if (in_array($p_id,$include_id, TRUE))
{
?>
<div class='choose-local'>
<div class='data-section'>
<span style="">Available Locally from :</span>
</div>
<div class="data-section">
<?php
if ($currentCountry =="CA")
{
?>
<span>Link 1<a href='https://www.link1.com'>[Order from here]</a></span>
<?php
}
if ($currentCountry =="US")
{
?>
<span>Link 2<a href='https://www.link2.com'>[Order from here]</a></span>
<?php
}
?>
</div>
</div>
<?php
}
}
?>

check weather your $p_id is string or int
<?php
$currentCountry = "CA";
if ($currentCountry =="CA" || $currentCountry =="US")
{
$p_id = 125;
$include_id = array(546, 125,135);
?>
<style>
.choose-local {
display: flex;
}
.data-section {
min-width: 33%;
}
.choose-local .data-section span {
float: left;
}
</style>
<?php
if (in_array($p_id,$include_id, TRUE))
{
?>
<div class='choose-local'>
<div class='data-section'>
<span style="">Available Locally from :</span>
</div>
<div class="data-section">
<?php
if ($currentCountry =="CA")
{
?>
<span>Link 1<a href='https://www.link1.com'>[Order from here]</a></span>
<?php
}
if ($currentCountry =="US")
{
?>
<span>Link 2<a href='https://www.link2.com'>[Order from here]</a></span>
<?php
}
?>
</div>
</div>
<?php
}
}
?>

Related

Why i have a little space in my background position

First please look to the picture to know what different
Sample picture
my css & html is like this:
#media screen and (max-width: 360px) {
.bg-product {
background-image: url(../../assets/img/home/mobile/3.png);
position: absolute;
}
}
<div class="col-12 px-0">
<a href="<?php echo site_url($link_product) . $link ?>" class="link-default">
<h2 class="h5 product-background">
<?php echo $value->item_name; ?>
</h2>
<p class="my-0 product-background">
<?php
if ($value->item_discount != 0 ) {
?>
<strike class="text-discount product-background"><?php echo currency_display($value->$price); ?></strike>
<?php
if($value->item_discount >= 10) {
?>
<span class="text-nowrap product-background"><?php echo $value->item_discount . '% Off' ?></span>
<?php
}
?>
<?php
}
?>
</p>
<p class="price-product bg-product">
<?php
if ($value->item_discount != 0 ) {
echo currency_display($value->$price - ($value->$price * ($value->item_discount/100)));
}else {
echo currency_display($value->$price);
}
?>
</p>
</a>
</div>
its for mobile version, i have some problem why i have space like that in my view, where i call a function for discount price , the space is apear between the real price and discount prince
Please try using background-size: cover -
.bg-product {
background-image: url(../../assets/img/home/mobile/3.png);
position: absolute;
background-size: cover;
}

How to display elements of array, grouped by two in one <div>

I have an array of elements. I need to display all the elements on the page, grouped by two in one 'div'
like this:
<div class='row'>
<article id='1'>item 1 row 1</article>
<article id='2'>item 2 row 1</article>
</div>
<div class='row'>
<article id='3'>item 1 row 2</article>
<article id='4'>item 2 row 2</article>
</div>
This my current php and html code:
<?php if ($arg['teasers']) foreach ($arg['teasers'] as $id => $article)
{ ?>
<div class="shops_<?php echo ($article['show'])?'fair':'draft'; ?> more">
<div class="shops_title">
<?php echo $article['title']; ?>
</div>
<div class="shops_teaser" onclick="window.location='<?php echo $arg['linkbase'].'/?id='.$id ?>'">
<?php echo $article['teaser']; ?>
</div>
<?php show_button_detail(array('uri'=>$arg['linkbase'].'/?id='.$id)); ?>
</div>
<?php
} ?>
Perfect example: http://tympanus.net/codrops/category/tutorials/
Maybe you could try something like this:
/* div.more */
div.row {
display: table-row;
width: 100%; /* your parent element should specify a width for this to work */
}
/* div.more > div[class^="shops_"] */
div.row > article {
display: table-cell;
width: 50%;
}

show feedback only when asked

I'm creating a feedback. I show the success message when it's good and error when there is something wrong, but my css (red and green block) is there from the beginning. How can I hide this before there is feedback?
<div id="feedback_success">
<?php if(empty($feedback_success)) { ?>
<h1 ></h1>
<?php } else { ?>
<h1><?php echo $feedback_success ?></h1>
<?php } ?>
</div>
<div id="feedback_error">
<?php if(empty($feedback_error)) { ?>
<h1 ></h1>
<?php } else { ?>
<h1><?php echo $feedback_error ?></h1>
<?php } ?>
</div>
css
#feedback_success
{
background-color: #45e589;
color: white;
padding:10px;
font-size:1.0em;
}
#feedback_error
{
background-color: #ff5555;
color: white;
padding:10px;
font-size:1.2em;
}
I think what you are asking is how to do this
<?php if(!empty($feedback_success)): ?>
<div id="feedback_success">
<h1><?php echo $feedback_success ?></h1>
</div>
<?php endif; ?>
<?php if(!empty($feedback_error)): ?>
<div id="feedback_error">
<h1><?php echo $feedback_error ?></h1>
</div>
<?php endif; ?>

jQuery cycle prev/next button images

I'm using Drupal 7 and Field Slideshow plugin. I published my slide and working. It's have a pager and that's name 'Prev' and 'Next'
I don't want text, must image. How can i do it?
<div id="field-slideshow-<?php print $slideshow_id; ?>-controls" class="field-slideshow-controls">
<?php print t('Prev'); ?>
<?php if (!empty($controls_pause)) : ?>
<?php print t('Play'); ?>
<?php print t('Pause'); ?>
<?php endif; ?>
<?php print t('Next'); ?>
</div>
<div id="field-slideshow-<?php print $slideshow_id; ?>-controls" class="field-slideshow-controls">
<?php if (!empty($controls_pause)) : ?>
<?php print t('Play'); ?>
<?php print t('Pause'); ?>
<?php endif; ?>
</div>
And styles like this:
.prev {
display:inline-block;
width:20px;
height:20px;
background: transparent url('path/to/prev/image.png') no-repeat center center;
}
.next {
display:inline-block;
width:20px;
height:20px;
background: transparent url('path/to/next/image.png') no-repeat center center;
}
Or you can have something like this:
<div id="field-slideshow-<?php print $slideshow_id; ?>-controls" class="field-slideshow-controls">
<img scr="path/to/prev/image.png" alt="<?php print t('Prev'); ?>" />
<?php if (!empty($controls_pause)) : ?>
<?php print t('Play'); ?>
<?php print t('Pause'); ?>
<?php endif; ?>
<img scr="path/to/next/image.png" alt="<?php print t('Next'); ?>" />
</div>

Using Custom Field to pull in image - if no img can the DIV not display? WordPress / php / CSS

This is what I am using:
<div class="banner">
<?php if(get_post_meta($post->ID, 'banner', true)) : ?>
<img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" />
<?php else : ?>
<?php the_title(); ?>
<?php endif; ?>
<div>`
and..
#banner {
clear:both;
width:980px;
overflow: hidden;
background: #F4F5F6;
padding:12px 0;
margin: 0 0 15px 0;
-moz-border-radius:15px;
-webkit-border-radius: 15px;
border-radius: 15px; /* future proofing */
-khtml-border-radius:15px; /* for old Konqueror browsers */
}
#banner img {display: block; margin:0 auto;}
I don't want a title displayed so that if/else is not necessary.
If there is no img / the custom field is not being used, can the div just not show? Right now if the custom field is not being used it is still showing an empty div.
SOLVED IT!!! Sorry for even posting here. Though it's not pretty, it works.
<div id="bannerHolder">
<?php if(get_post_meta($post->ID, 'banner', true)) : ?>
<div id="banner">
<img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" />
</div><!--banner-->
<?php else : ?>
<?php endif; ?>
</div><!--bannerholder-->
Put the if clause around the div, not inside:
<?php
if ($banner = get_post_meta($post->ID, 'banner', true))
{
echo '<div class="banner">', $banner, '</div>';
}
?>
Put the if clause encapsulating the div element and remove the else part of the php sentence.
Example:
<?php if(get_post_meta($post->ID, 'banner', true)) : ?>
<div class="banner">
<img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" />
<div>
<?php endif; ?>

Categories