Bootstrap Templates Bundle

Tuesday, February 3, 2015

Display the number of Products Sold in WooCommerce

//To display the number of units sold for a product, add the following snippet of code to your theme’s functions.php file

<?php
add_action( 'woocommerce_single_product_summary', 'wc_product_sold_count', 11 );
function wc_product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->id, 'total_sales', true );
echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}
?>

//or Where You want to show

<?php echo get_post_meta($post->ID, 'total_sales', true); ?> 



Monday, February 2, 2015

php if else sample code

This code is for those, who are facing problem with php if else


Sample 1: 


<?php if (condition): ?>
html code to run if condition is true
<?php else: ?>
html code to run if condition is false
<?php endif ?>

Sample 2: 


<?php
if(condition) { ?> 
html code to run if condition is true
<?php } ?>


Sample 3: 


<?php
     $var=1;
     if($var == 2) {
          echo “The if statement is true”;
         // or any html code to run if condition is true
     } else {
          echo “The if statement is not true”;
        // or any html code to run if condition is true
     }

?>


Sample 4:  

 The if…elseif…else Statement



<?php 
 $var=1; 
 $var2=1; 
 if($var == 2) { 
 echo “The if statement is true”; 
 } 
elseif($var == $var2) { 
 echo “The second if statement is true”; 
 } 
else { 
 echo “None of the first if statement where true”; 
 } 
?>


Sample 5:

<?php 
if ( $number_three == 3 ) {
echo "The if statement evaluated to true";
} else {
echo "The if statement evaluated to false";
}
?>

Furniture Shopify Theme

Furnish - Minimal Furniture Shopify Theme Furnish – Minimalist Shopify Theme is a clean and elegant design – suitable for sellin...