Skip to content

Instantly share code, notes, and snippets.

@stephanieland352
Created November 27, 2018 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephanieland352/d3a6e1d8f648bda27589ffc555e59796 to your computer and use it in GitHub Desktop.
Save stephanieland352/d3a6e1d8f648bda27589ffc555e59796 to your computer and use it in GitHub Desktop.
Goals Thermometer
<?php
global $wp_query;
$maincat = $wp_query->get_queried_object();
$cat_id = $maincat->term_id;
$goals = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id', //This is optional, as it defaults to 'term_id'
'terms' => 55,
'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
)
)
);
$goalsloop = new WP_Query($goals); ?>
<?php if ($goalsloop->have_posts()) : ?>
<section class="goals">
<?php
$y=0; while ( $goalsloop->have_posts() ) : $goalsloop->the_post(); $y++; global $product; ?>
<?php if( $y == 1 ): ?>
<div class="row">
<?php endif; ?>
<?php get_template_part('goals/goal-single'); ?>
<?php if( $y == 5 ): $y = 0; ?>
</div>
<?php endif; ?>
<?php endwhile; wp_reset_query(); ?>
<?php if ($y%5 != 0) echo "</div>"; ?>
</section>
<?php endif; ?>
<div class="goal <?php if (is_single()) { echo 'single'; } else { echo 'archive';} if (is_handheld()){echo ' mobile';} else{echo ' notmobile';} ?>">
<div class="goal-cat">
<?php $prodid = get_the_ID();
$img_url = wp_get_attachment_image_src( get_post_thumbnail_id( $prodid ), 'single-post-thumbnail' );
?>
<a href="<?php echo the_permalink(); ?>" title="<?php the_title(); ?>">
<div class="goal-title goal-cat-title"><?php the_title(); ?></div>
<div class="goal-image">
<?php if ($img_url) { ?>
<img src="<?php echo $img_url[0]; ?>" alt="<?php the_title(); ?>">
<?php } else { ?>
<img src="<?php echo wc_placeholder_img_src(); ?>" alt="<?php the_title(); ?>">
<?php } ?>
</div>
</a>
<!-- Progress BAR -->
<?php get_template_part('goals/progress-bar'); ?>
<!-- / Progress BAR -->
<!-- QUICK VIEW -->
<div class="quick-view-button">
<div class="button alt">
Contribute
</div>
</div>
<?php get_template_part('goals/quick-view'); ?>
<!-- /Quick view -->
</div>
<!--Goal Item -->
<?php if( have_rows('items_needed', $prodid) ): ?>
<div class="items-needed ">
<?php $x=0; while( have_rows('items_needed', $prodid) ): the_row(); if( get_sub_field('goal_complete') ==false) : $x++; ?>
<div class="goal-product">
<div class="topbar"></div>
<div class="number"><?php echo $x; ?></div>
<div class="goal-product-title"><?php the_sub_field('title'); ?></div>
<div class="goal-product-description">
<?php
$description = get_sub_field('description');
if (strlen($description) > 112 && !is_single()) {
echo substr($description, 0, 100) . '...<a href="'.esc_url( get_permalink($prodid) ).'#anchor-'.$x.'">View More</a>'; } else {
echo $description;
} ?></div>
</div>
<?php endif; endwhile; ?>
</div>
<?php endif; ?>
<!-- /Goal Item -->
</div>
<div class="progress-bar">
<!-- Total -->
<?php
$prodid = get_the_ID();
if( have_rows('items_needed', $prodid) ):
$total = 0;
while( have_rows('items_needed', $prodid) ): the_row();
$total += intval( get_sub_field('amount_needed' ) );
endwhile; endif; ?>
<!-- Total Needed -->
<?php
if( have_rows('items_needed', $prodid) ):
$totalneeded = 0;
while( have_rows('items_needed', $prodid) ): the_row(); if( get_sub_field('goal_complete') ==false) :
$totalneeded += intval( get_sub_field('amount_needed' ) ); ?>
<?php endif; endwhile; endif; ?>
<!-- Total Accomplished -->
<?php
if( have_rows('items_needed', $prodid) ):
$total_accomplished = 0;
while( have_rows('items_needed', $prodid) ): the_row(); if( get_sub_field('goal_complete') ==false) :
$total_accomplished += intval( get_sub_field('amount_given' ) ); ?>
<?php endif; endwhile; endif; ?>
<!-- Repeater -->
<?php
$fill= dw_product_totals();
if( have_rows('items_needed', $prodid) ): ?>
<?php
$opengoals = false;
while( have_rows('items_needed', $prodid) ): the_row();
$i = count( get_field('items_needed', $prodid) );
if( get_sub_field('goal_complete') ==false) {
$opengoals = true;
$amount = get_sub_field('amount_needed');
$calc = $amount/$totalneeded * 100 ; ?>
<div class="bar" style="width: <?php echo number_format((float)$calc, 2, '.', '');; ?>%">
</div>
<?php } endwhile;
if($opengoals === false) { ?>
<div class="bar" style="width:100%"></div>
<?php }
?>
<?php $fillamount = $total_accomplished/$totalneeded *100; ?>
<?php else: ?>
<?php $fill= dw_product_totals();
$fillamount = $fill/50000000 * 100; ?>
<div class="bar" style="width:100%"></div>
<?php endif; ?>
<div class="progress-fill" style="width:<?php echo number_format((float)$fillamount, 2, '.', ''); ?>%"> </div>
</div>
<div class="total-needed">
<?php $coltotal = $totalneeded-$total_accomplished;
// echo $totalneeded. '-<br> ';
// echo $total_accomplished. '=<br> ';
if($coltotal ===0) {
echo 'TBD';
} else {
echo '$'. $coltotal.' Needed';
}
?>
</div>
<?php global $product; ?>
<div class="product-quick-view">
<div class="quick-view">
<a class="close" href="#"><i class="fa fa-times"></i></a>
<div class="goal-title"><?php the_title(); ?></div>
<?php $desc = get_the_content();
if($desc != '') { ?>
<div class="goal-description"><?php the_content(); ?></div>
<?php }
if (get_field('product_quick_view_cta','options')) { ?>
<div class="goal-cta"> <?php the_field('product_quick_view_cta','options'); ?></div>
<?php } ?>
<form class="donation-amounts">
<ul>
<li class="set-amount"><input type="radio" name="donation" id="donate5" value="5" /><label for="donation">$5</label></li>
<li class="set-amount"><input type="radio" name="donation" id="donate10" value="15"/><label for="donate10">$15</label></li>
<li class="enter-amount"><input type="radio" name="donation" id="donateother" value="other"/> <label for="donateother">Other Amount</label></li>
</ul>
<?php
$rows = get_field('items_needed', $product->id);
if($rows) { ?>
<p style="text-align:center">or</p>
<ul class="remainder">
<?php
$i = 0;
foreach($rows as $row) {
$i++;
$wanted = $row['amount_needed'];
$given = $row['amount_given'];
$needed = $wanted - $given;
$completed = $row['goal_complete'];
// if they are NOT complete
if (! $completed ) {
?>
<li class="set-amount"><input type="radio" name="donation" id="donateremainder" value="<?php echo $needed; ?>"/> <label for="donateremainder">$<?php echo $needed; ?> <small>(Remainder To Meet Goal)</small></label></li>
<?php
break;
}
} ?>
</ul> <?php
}
?>
</form>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment