create custom post type category

/***********************create custom post type category***************************************/
add_action( ‘init’, ‘sk_add_category_taxonomy_to_events’ );
function sk_add_category_taxonomy_to_events() {
register_taxonomy_for_object_type( ‘category’, ‘custom_events’ );
}

WordPress Woocommerce – AJAX based Add to Cart for Variables

add following code to function php
add_action( ‘wp_ajax_woocommerce_add_to_cart_variable_rc’,’woocommerce_add_to_cart_variable_rc_callback’ );
add_action( ‘wp_ajax_nopriv_woocommerce_add_to_cart_variable_rc’,’woocommerce_add_to_cart_variable_rc_callback’ );
function woocommerce_add_to_cart_variable_rc_callback() {

$product_id = apply_filters( ‘woocommerce_add_to_cart_product_id’, absint( $_POST[‘product_id’] ) );
$quantity = empty( $_POST[‘quantity’] ) ? 1 : apply_filters( ‘woocommerce_stock_amount’, $_POST[‘quantity’] );
$variation_id = $_POST[‘variation_id’];
$variation  = $_POST[‘variation’];
$passed_validation = apply_filters( ‘woocommerce_add_to_cart_validation’, true, $product_id, $quantity );

if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation  ) ) {
do_action( ‘woocommerce_ajax_added_to_cart’, $product_id );
if ( get_option( ‘woocommerce_cart_redirect_after_add’ ) == ‘yes’ ) {
wc_add_to_cart_message( $product_id );
}

// Return fragments
$this->get_refreshed_fragments();
} else {
$this->json_headers();

// If there was an error adding to the cart, redirect to the product page to show any errors
$data = array(
‘error’ => true,
‘product_url’ => apply_filters( ‘woocommerce_cart_redirect_after_error’, get_permalink( $product_id ), $product_id )
);
echo json_encode( $data );
}
die();
}

change the variable button to – need to add product_type_variable class instead of ajax_add_to_cart class

 

<button type=”submit” class=”product_type_variable button alt btn-add add_to_cart_button” data-product_id=”<?php echo $product->id;?>” data-product_sku=”<?php echo $product->get_sku();?>” data-quantity=”1″><?php echo $product->single_add_to_cart_text(); ?></button>

 

add following js to ur theme derectory named: add-to-cart-variable.js and add to link to footer

vjQuery( function( $ ) {

// wc_add_to_cart_params is required to continue, ensure the object exists
if ( typeof wc_add_to_cart_params === ‘undefined’ )
return false;

// Ajax add to cart
$( document ).on( ‘click’, ‘.product_type_variable’, function() {

$variation_form = $( this ).closest( ‘.variations_form’ );
var var_id = $variation_form.find( ‘input[name=variation_id]’ ).val();
var att_type = $variation_form.find( ‘select[name=attribute_weight]’ ).val();
var qty = $variation_form.find( ‘input[name=quantity]’ ).val();

// AJAX add to cart request

var $thisbutton = $( this );

if ( $thisbutton.is( ‘.product_type_variable’ ) ) {

if ( ! $thisbutton.attr( ‘data-product_id’ ) )
return true;

$thisbutton.removeClass( ‘added’ );
//$thisbutton.addClass( ‘loading’ );
$thisbutton.addClass(“loading”).trigger(“loadingEvent”);
var data = {
action: ‘woocommerce_add_to_cart_variable_rc’,
product_id: $thisbutton.attr( ‘data-product_id’ ),
quantity: qty,//$thisbutton.attr( ‘data-quantity’ ),
variation_id: var_id,
variation: { weight: att_type }
};

// Trigger event
$( ‘body’ ).trigger( ‘adding_to_cart’, [ $thisbutton, data ] );

// Ajax action
$.post( wc_add_to_cart_params.ajax_url, data, function( response ) {

if ( ! response )
return;

var this_page = window.location.toString();

this_page = this_page.replace( ‘add-to-cart’, ‘added-to-cart’ );

if ( response.error && response.product_url ) {
window.location = response.product_url;
return;
}

// Redirect to cart option
if ( wc_add_to_cart_params.cart_redirect_after_add === ‘yes’ ) {

window.location = wc_add_to_cart_params.cart_url;
return;

} else {

$thisbutton.removeClass( ‘loading’ );

fragments = response.fragments;
cart_hash = response.cart_hash;

// Block fragments class
if ( fragments ) {
$.each( fragments, function( key, value ) {
$( key ).addClass( ‘updating’ );
});
}

// Block widgets and fragments
$( ‘.shop_table.cart, .updating, .cart_totals’ ).fadeTo( ‘400’, ‘0.6’ ).block({ message: null, overlayCSS: { background: ‘transparent url(‘ + wc_add_to_cart_params.ajax_loader_url + ‘) no-repeat center’, backgroundSize: ’16px 16px’, opacity: 0.6 } } );

// Changes button classes
$thisbutton.addClass( ‘added’ );

// View cart text
if ( ! wc_add_to_cart_params.is_cart && $thisbutton.parent().find( ‘.added_to_cart’ ).size() === 0 ) {
$thisbutton.after( ‘ <a class=”added_to_cart wc-forward” title=”‘ + wc_add_to_cart_params.i18n_view_cart + ‘” href=”‘ + wc_add_to_cart_params.cart_url + ‘”>’ + wc_add_to_cart_params.i18n_view_cart + ‘</a>’ );
}

// Replace fragments
if ( fragments ) {
$.each( fragments, function( key, value ) {
$( key ).replaceWith( value );
});
}

// Unblock
$( ‘.widget_shopping_cart, .updating’ ).stop( true ).css( ‘opacity’, ‘1’ ).unblock();

// Cart page elements
$( ‘.shop_table.cart’ ).load( this_page + ‘ .shop_table.cart:eq(0) > *’, function() {

$( ‘div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)’ ).addClass( ‘buttons_added’ ).append( ‘<input id=”add1″ class=”plus” type=”button” value=”+” />’ ).prepend( ‘<input id=”minus1″ class=”minus” type=”button” value=”-” />’ );

$( ‘.shop_table.cart’ ).stop( true ).css( ‘opacity’, ‘1’ ).unblock();

$( ‘body’ ).trigger( ‘cart_page_refreshed’ );
});

$( ‘.cart_totals’ ).load( this_page + ‘ .cart_totals:eq(0) > *’, function() {
$( ‘.cart_totals’ ).stop( true ).css( ‘opacity’, ‘1’ ).unblock();
});

// Trigger event so themes can refresh other areas
$( ‘body’ ).trigger( ‘added_to_cart’, [ fragments, cart_hash ] );

}
});

return false;

}

return true;
});

});

 

 

 

 

add following js to footer for single product

jQuery(function($) {

$(“form.cart”).on(“change”, “input.qty”, function() {
$(this.form).find(“button[data-quantity]”).data(“quantity”, this.value);
});

});

$(document.body).on(“added_to_cart”, function() {
window.location.reload();
$(‘html, body’).animate({scrollTop : 0},800);
});

$(‘.product_type_variable’).on(‘loadingEvent’, function () {

$(‘html, body’).animate({scrollTop : 0},800);
alert(window.location.tostring());
});

 

check these links for more informations

https://teckstack.com/wordpress-woocommerce-ajax-based-add-cart-variables

 

http://stackoverflow.com/questions/33374869/updating-woocommerce-cart-after-adding-a-variable-product-ajax

Woocommerce Ajax add to cart for variable products

WordPress Blog Archive Template with Pagination

<?php
/* Template Name: archive */
?>
<?php get_header();  ?> 
                                  
                                         
<!-- inner banner-wrapper end -->                                                  
                         
                        
                        

' . get_the_date() . '' );                             elseif ( is_month() ) :                               printf( __( 'MONTHLY NEWS ARCHIVES: %s', 'twentytwelve' ), '' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentytwelve' ) ) . '' );                             elseif ( is_year() ) :                               printf( __( 'YEARLY NEWS ARCHIVES: %s', 'twentytwelve' ), '' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentytwelve' ) ) . '' );                             else :                               _e( 'LATEST NEWS ARCHIVES', 'twentytwelve' );                             endif;                           ?>                         

                         single post else';                                 }                                                    if (have_posts()) : while (have_posts()): the_post();                                                          ?>
                             

">

                                                                                            

                              " class="read-more">Read More >                          
<!-- news unit end --> <?php endwhile; else: ?>                             <p><?php _e('Sorry, no records matched your criteria.'); ?></p>                         <?php endif; wp_reset_query(); ?>                                          </div><!-- right content end --> <!-- SIDEBAR WARAPPER END -->                                                  
                                                      

                                                                              
<!-- common-text-area end -->                                              </div><!-- inner end -->                 </div><!-- inner-content-wrapper end -->                             </div><!-- content-wrapper end -->                             <?php get_footer(); ?>   

How to reorder billing fields in WooCommerce Checkout template

add_filter("woocommerce_checkout_fields", "order_fields");

function order_fields($fields) {

    $order = array(
        "billing_first_name", 
        "billing_last_name", 
        "billing_company", 
        "billing_address_1", 
        "billing_address_2", 
        "billing_postcode", 
        "billing_country", 
        "billing_email", 
        "billing_phone"

    );
    foreach($order as $field)
    {
        $ordered_fields[$field] = $fields["billing"][$field];
    }

    $fields["billing"] = $ordered_fields;
    return $fields;

}

get woocommerce category image

add_action(‘woocommerce_display_banner’, ‘woocommerce_category_image’, 2);

function woocommerce_category_image() {
if (is_product_category()) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta($cat->term_id, ‘thumbnail_id’, true);

$thumbnail = wp_get_attachment_image($thumbnail_id, ‘full’, false, array(‘class’=>’category_thumb’));

if ($thumbnail) {
echo $thumbnail;

}
}
}

Working with Nested Repeaters – Advanced Custom Fields

$related=array();

if (have_rows(‘related_products_list’,’option’)):
while (have_rows(‘related_products_list’,’option’)): the_row();
$prod = get_sub_field(‘product’);

$related_product = get_sub_field(‘related_product’);

while(has_sub_field(‘related_product’)):
$itm = get_sub_field(‘item’);
array_push($related,$itm->ID);
endwhile;

endwhile;
endif;

Cart total updates with ajax js in all pages

To work shipping method code in all the pages

 

add_action(‘wp_enqueue_scripts’, ‘child_manage_woocommerce_styles’, 99);

function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action(‘wp_head’, array($GLOBALS[‘woocommerce’], ‘generator’));

//first check that woo exists to prevent fatal errors
if (function_exists(‘is_woocommerce’)) {
$suffix               = defined( ‘SCRIPT_DEBUG’ ) && SCRIPT_DEBUG ? ” : ‘.min’;
$lightbox_en          = ‘yes’ === get_option( ‘woocommerce_enable_lightbox’ );
$ajax_cart_en         = ‘yes’ === get_option( ‘woocommerce_enable_ajax_add_to_cart’ );
$assets_path          = str_replace( array( ‘http:’, ‘https:’ ), ”, WC()->plugin_url() ) . ‘/assets/’;
$frontend_script_path = $assets_path . ‘js/frontend/’;

wp_enqueue_script( ‘wc-cart’, $frontend_script_path . ‘cart’ . $suffix . ‘.js’, array( ‘jquery’, ‘wc-country-select’, ‘wc-address-i18n’ ) );

wp_localize_script( ‘wc-cart’, ‘wc_cart_params’, apply_filters( ‘wc_cart_params’, array(
‘ajax_url’                     => WC()->ajax_url(),
‘wc_ajax_url’                  => WC_AJAX::get_endpoint( “%%endpoint%%” ),
‘ajax_loader_url’              => apply_filters( ‘woocommerce_ajax_loader_url’, $assets_path . ‘images/ajax-loader@2x.gif’ ),
‘update_shipping_method_nonce’ => wp_create_nonce( “update-shipping-method” ),
) ) );

}

}

Create a blog template with pagination

<?php
$args = array(‘post_type’ => ‘post’, ‘posts_per_page’ => 3,’orderby’ => ‘date desc’);
$loop = new WP_Query($args);
$i=0;
while ($loop->have_posts()) : $loop->the_post(); $i++;
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), ‘full’,true );

?>

post_count) echo ” last-child”; ?>”>


” width=”” height=”” />

</div><!–blog block end–>

<?php endwhile; ?>
<?php wp_reset_query(); ?>

</div><!–left content area end–>