woocommerce display variable product price

// Display Price For Variable Product With Same Variations Prices
add_filter('woocommerce_available_variation', function ($value, $object = null, $variation = null) {
    if ($value['price_html'] == '') {
        $value['price_html'] = '<span class="price">' . $variation->get_price_html() . '</span>';
    }
    return $value;
}, 10, 3);

refresh fragments of the cart page

// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)

add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');

function woocommerce_header_add_to_cart_fragment( $fragments ) 
{
    global $woocommerce;
    ob_start(); ?>

    <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> <?php echo $woocommerce->cart->get_cart_total(); ?></a>

    <?php
    $fragments['a.cart-contents'] = ob_get_clean();
    return $fragments;
}

cart.php code

this is refresh fragments of the cart page.

load cart template with ajax

//add this code to function.php

add_action( ‘wp_ajax_nopriv_load_woo_cart’, ‘load_woo_cart’ );
add_action( ‘wp_ajax_load_woo_cart’, ‘load_woo_cart’ );

function load_woo_cart(){

WC()->cart->calculate_totals();

WC()->cart->calculate_shipping();

$packages = WC()->shipping->get_packages();

echo wc_get_template( ‘cart/cart.php’ );
die();
}

javascript

 

$(document).ready(function() {
$(“.ajax_add_to_cart”).click(function(){

var $myDiv = $(‘.shop_table’);

if (!$myDiv.length){
var this_page = window.location.toString();
var data = {
‘action’: ‘load_woo_cart’
};

jQuery.post( woocommerce_params.ajax_url, data, function( response ) {
jQuery( ‘#right-sidebar-wrapper’ ).html( response );
});
//you can now reuse  $myDiv here, without having to select it again.
}
});
});

 

 

Create Custom menu items to wp_nav_menu

add_filter( ‘wp_nav_menu_objects’, ‘ravs_add_menu_parent_class’,10,2 );
function ravs_add_menu_parent_class( $items, $args ) {

if ($args->menu == ‘main-menu’||$args->menu == ‘mobile-menu’) {
// add parent item
$item = array (
‘title’            => ‘Brands’,
‘menu_item_parent’ => 0,
‘ID’               => 999999999999876, //an unlikely, high number
‘db_id’            => 999999999999876, //an unlikely, high number
‘url’              => ‘#’
);
$new_links[] = (object) $item;
unset( $item );

// get woocommerce attribe call brands
$terms = get_terms( ‘pa_brand’, array(‘hide_empty’=>true) );

// add childs
foreach ($terms as $term) :
$term_link = home_url().’/shop/?filters=brand’.’%5B’.$term->term_id.’%5D’;
$label = $term->name;
$link = $term_link;
$item = array(
‘title’            => $term->name,
‘menu_item_parent’ => ‘999999999999876’,
‘ID’               => $term->term_id,
‘db_id’            => ”,
‘url’              => $link,
‘classes’          => array( ‘sub-menu-item’ )
);

// get the URL

$new_links[] = (object) $item;  // Add the new menu item to our array
unset( $item );

endforeach;

$index = count( $items ) – 2;  // Insert before the last two items

// Insert the new links at the appropriate place.
array_splice( $items, $index, 0, $new_links );

}
return $items;
}

WP ecommerce – Customize Breadcrumbs

How to customise WP e-Commerce Breadcrumbs

I’m posting this here as there doesn’t seem to be any documentation on how to do this. The WP e-Commerce plugin is a decent shopping cart plugin for WordPress, unfortunately it’s documentation is rather poor!

The breadcrumbs (once enabled via the settings in the admin panel) display a breadcrumb trail on your product pages. by default is looks something like this:

Store Name » Products Page » Category Name » Product Name

To edit the output you need to edit the function in the theme files. The function is:

<?php wpsc_output_breadcrumbs (); ?>

You can pass an array of arguments to the function. Your options are:

'before-breadcrumbs' => '<div>',
'after-breadcrumbs'  => '</div>',
'before-crumb'       => '',
'after-crumb'        => '',
'crumb-separator'    => ' &raquo; ',
'show_home_page'     => true,
'show_products_page' => true,
'echo'               => true

Now simply pass your arguments to the function, for example:

<?php wpsc_output_breadcrumbs ( array (
 'crumb-separator'    => ' &gt; ',
 'show_home_page'     => false,   
) ); ?>

The above would display breadcrumbs with ‘>’ as a separator and removes the homepage:

Products Page > Category Name > Product Name

I also think its best to put your breadcrumb function in a separate file e.g ‘wpsc-breadcrumbs.php’ then include it in each instance:

<? include "wpsc-breadcrumbs.php"; ?>

This way you don’t need to edit it multiple times should you decide to change something in the future.

Original Post : http://www.siteart.co.uk/how-to-customise-edit-wp-e-commerce-breadcrumbs

How to get password characters in an Input field while retaining a text as initial value

By modifying a typical input type “text” in this method will enable you to achieve this.

This is done by prompting an event using javascript to dynamically to change the input type to password when clicking on the input box. And also changing it back to a normal input when no text is entered and the input loses its focus.

<input
  type="text"
  onblur="this.value=!this.value?'Password':this.value;"
  onfocus="this.select()"
  onclick="if (this.value=='Password'){this.value=''; this.type='password'}"
  name="pwd"
  id="user_pass"
  class="input"
  value="Password"
  size="20"

Demo:- http://jsfiddle.net/cgP5K/1/

 

Using the Loop

The Loop should be placed in index.php and in any other Templates used to display post information.

Be sure to include the call for the header template at the top of your Theme‘s templates. If you are using The Loop inside your own design (and your own design is not a template), set WP_USE_THEMES to false:

<?php define('WP_USE_THEMES', false); get_header(); ?>

The loop starts here:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

and ends here:

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

This is using PHP’s alternative syntax for control structures, and could also be expressed as:

<?php 
	if ( have_posts() ) {
		while ( have_posts() ) {
			the_post(); 
			//
			// Post Content here
			//
		} // end while
	} // end if
?>