Pages

Showing posts with label Woocommerce. Show all posts
Showing posts with label Woocommerce. Show all posts

Monday, April 14, 2014

Woocommerce change error message OR repalce default message - [resolved]

If you want to change default messages in woocommerce than you have to write below code in functions.php

function sagepay_woocommerce_add_error( $error ) {
    if( 'SagePay Direct - Card number required.' == $error ) {
        $error = 'Card number required.';
    } else if( 'SagePay Direct - Fullname required.' == $error ) {
        $error = 'Fullname required.';
    } else if( 'SagePay Direct - CV2 required.' == $error ) {
        $error = 'CV2 required.';
    }
    return $error;
}
add_filter( 'woocommerce_add_error', 'sagepay_woocommerce_add_error' );

Woocommerce Change/Remove Payment Gateway Icon-[resolved]

If anyone wants to change payment gateway details than he can do this from below way.
Please write "woocommerce_available_payment_gateways" hook in functions.php

function remove_sagepage_payment_gateway_icon( $gateways ) {
if(isset($gateways['sagepaydirect'])){
$gateways['sagepaydirect']->icon = '';
}
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'remove_sagepage_payment_gateway_icon' );

Thursday, April 3, 2014

Woocommerce get top level category - [resolved]

function get_top_level_product_cat(){
    global $post;
    $prod_terms = get_the_terms( $post->ID, 'product_cat' );
    foreach ($prod_terms as $prod_term) {

        // gets product cat id
        $product_cat_id = $prod_term->term_id;

        // gets an array of all parent category levels
        $product_parent_categories_all_hierachy = get_ancestors( $product_cat_id, 'product_cat' ); 
       
        // This cuts the array and extracts the last set in the array
        $last_parent_cat = array_slice($product_parent_categories_all_hierachy, -1, 1, true);
        foreach($last_parent_cat as $last_parent_cat_value){
            return $product_category = get_product_category_by_id( $last_parent_cat_value );           
        }
    }
}

function get_product_category_by_id( $category_id ) {
    $term = get_term_by( 'id', $category_id, 'product_cat', 'ARRAY_A' );
    return $term['name'];
}

Saturday, September 7, 2013

Woocommerce Products show on homepage with pagination

Please first install "WP-Pagenavi" plugin to your store.
and then write below code to your home page template.

<?php
                // Setup your custom query
                global $paged;
                if( get_query_var( 'paged' ) )
                $my_page = get_query_var( 'paged' );
                else {
                if( get_query_var( 'page' ) )
                $my_page = get_query_var( 'page' );
                else
                $my_page = 1;
                set_query_var( 'paged', $my_page );
                $paged = $my_page;
                }
                $args = array( 'post_type' => 'product', 'paged' => $my_page, 'posts_per_page' => 8 );
                $loop = new WP_Query( $args );
                //print_r($loop);
                echo '<ul>';
                while ( $loop->have_posts() ) : $loop->the_post();
                   
                    echo '<li class="product">';
                            echo '<a class="prod_image" href="'.esc_url( get_permalink( $post->ID ) ).'" title="'.esc_attr($post->post_title ? $post->post_title : $post->ID).'">';
                            if ( has_post_thumbnail($post->ID) ) {
                                echo get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
                            } else {
                                echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );
                            }
                            echo '</a>';                               
                            if(get_post_meta( $post->ID, '_regular_price', true) != ''){
                                echo '<span class="price"><span class="amount">$'.number_format(get_post_meta( $post->ID, '_regular_price', true), 2, '.', '').'</span></span>';
                            } else {
                                echo '<span class="price"><span class="amount">&nbsp;</span></span>';
                            }
                            echo '<p>'.substr(strip_tags($post->post_content),0,25).'...</p>';
                            echo '<div class="info"><a href="'.get_permalink().'">INFO</a></div>';
                       
                    echo '</li>';
                endwhile;
                wp_pagenavi(array( 'query' => $loop ));
                wp_reset_query();
                ?>

Sunday, August 18, 2013

WooCommerce - Show number of items in cart and total

<?php global $woocommerce; ?>

<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>

Woocommerce - disable/removing products descriptions tabs

Please write below code in functions.php

add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {   
    unset( $tabs['description'] ); // Remove the description tab
    //unset( $tabs['reviews'] ); // Remove the reviews tab
    //unset( $tabs['additional_information'] ); // Remove the additional information tab
   
    return $tabs;
}

Monday, March 18, 2013

Hide other shipping methods when FREE SHIPPING is available - woocommerce



// Hide standard shipping option when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );

/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_standard_shipping_when_free_is_available( $available_methods ) {

if( isset( $available_methods['free_shipping'] ) AND isset( $available_methods['flat_rate'] ) ) {

// remove standard shipping option
if( isset( $available_methods['free_shipping'] ) ) {
$freeShipping = $available_methods['free_shipping'];
unset( $available_methods );

$available_methods['free_shipping'] = $freeShipping;
}
return $available_methods;
}

return $available_methods;
}

Friday, March 8, 2013

woocommerce redirect user to cart page after click on add to cart



Please write this code in functions.php file in wordpress theme

add_filter('add_to_cart_redirect', 'custom_add_to_cart_redirect');

function custom_add_to_cart_redirect() {
     return get_permalink(get_option('woocommerce_cart_page_id')); // Replace with the url of your choosing
}