Last active
August 26, 2021 22:27
-
-
Save mustafix/d73951218892ba0b7b1fbbe51cd7c10c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global $woocommerce; | |
//remove breadcrumb | |
remove_action('woocommerce_before_main_content','woocommerce_breadcrumb',20); | |
// Breadcumbs custom style(div or ul) | |
add_filter( 'woocommerce_breadcrumb_defaults', 'flipmart_woocommerce_breadcrumbs' ); | |
function flipmart_woocommerce_breadcrumbs() { | |
return array( | |
'delimiter' => '<span>›</span> ', | |
'wrap_before' => '<div class="breadcrumb-inner"><ul class="list-inline list-unstyled">', | |
'wrap_after' => '</ul></div>', | |
'before' => '', | |
'after' => '', | |
'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ), | |
); | |
} | |
<?php woocommerce_breadcrumb(); ?> | |
/*==================================================================== | |
WooCommerce Default Showing result remove | |
====================================================================*/ | |
remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count',20,0); | |
/*==================================================================== | |
WooCommerce Product rating remove | |
====================================================================*/ | |
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating',5,0); | |
/*==================================================================== | |
Change number or products per row | |
====================================================================*/ | |
add_filter('loop_shop_columns', 'loop_columns'); | |
if (!function_exists('loop_columns')) { | |
function loop_columns() { | |
return 4; // 4 products per row | |
} | |
} | |
/*==================================================================== | |
Custom Catalog Ordering | |
======================================================================*/ | |
//WooCommerce Default Catelog ordering remove | |
remove_action('woocommerce_before_shop_loop', 'woocommerce_catalog_ordering',30,0); | |
add_filter( 'woocommerce_catalog_orderby', 'woocommerce_custom_catalog_orderby' ); | |
function woocommerce_custom_catalog_orderby( $sortby ) { | |
echo '<span class="orderby" style="padding:7px 0px;font-weight:700;">Sort By :</span>'; | |
$sortby['menu_order'] ='Default sorting'; | |
$sortby['date'] ='Newness'; | |
$sortby['popularity'] ='Popularity'; | |
$sortby['price'] = 'Price: low to high'; | |
$sortby['price-desc'] = 'Price: high to low'; | |
unset($sortby['rating']); | |
return $sortby; | |
} | |
<?php woocommerce_catalog_ordering(); ?> | |
/*==================================================================== | |
Product item show per-page | |
======================================================================*/ | |
function product_show_per_page() { | |
$per_page = filter_input(INPUT_GET, 'perpage', FILTER_SANITIZE_NUMBER_INT); | |
echo '<div class="woocommerce-perpage">'; | |
echo '<span><b>Per Page:</b> </span>'; | |
echo '<select onchange="if (this.value) window.location.href=this.value">'; | |
$orderby_options = array( | |
'6' => '6 items', | |
'16' => '16 items', | |
'24' => '24 items', | |
'32' => '32 items', | |
'-1' => 'All items' | |
); | |
foreach( $orderby_options as $value => $label ) { | |
echo "<option ".selected( $per_page, $value )." value='?perpage=$value'>$label</option>"; | |
} | |
echo '</select>'; | |
echo '</div>'; | |
} | |
add_action( 'pre_get_posts', 'ps_pre_get_products_query' ); | |
function ps_pre_get_products_query( $query ) { | |
$per_page = filter_input(INPUT_GET, 'perpage', FILTER_SANITIZE_NUMBER_INT); | |
if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'product' ) ) { | |
$query->set( 'posts_per_page', $per_page ); | |
} | |
} | |
<?php product_show_per_page(); ?> | |
/*==================================================================== | |
Custom Pagination | |
======================================================================*/ | |
//WooCommerce Default pagination remove | |
remove_action('woocommerce_after_shop_loop', 'woocommerce_pagination',10,0); | |
function woocommerce_custom_pagination() { | |
global $wp_query; | |
$big = 999999999; // need an unlikely integer | |
$pages = paginate_links( array( | |
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), | |
'format' => '?paged=%#%', | |
'current' => max( 1, get_query_var('paged') ), | |
'total' => $wp_query->max_num_pages, | |
'prev_next' => true, | |
'type' => 'array', | |
'prev_next' => true, | |
'prev_text' => __(' '.'<i class="fa fa-angle-left"></i>'.' '), | |
'next_text' => __(' '.'<i class="fa fa-angle-right"></i>'.' '), | |
) ); | |
if( is_array( $pages ) ) { | |
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged'); | |
echo '<div class="pagination-container floatright"><ul class="list-inline list-unstyled">'; | |
foreach ( $pages as $page ) { | |
echo "<li>$page</li>"; | |
} | |
echo '</ul></div>'; | |
} | |
} | |
<?php woocommerce_custom_pagination(); ?> | |
/*==================================================================== | |
Add cat total | |
====================================================================*/ | |
//For html | |
<a class="cart-customlocation" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"> | |
<?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?> | |
</a> | |
//For function.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-customlocation" 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-customlocation'] = ob_get_clean(); | |
return $fragments; | |
} | |
/*==================================================================== | |
woocommerce_template_loop_add_to_cart | |
====================================================================*/ | |
function custom_woocommerce_product_add_to_cart_text() { | |
global $product; | |
$product_type = $product->product_type; | |
switch ( $product_type ) { | |
case 'external': | |
return __( 'Buy product', 'woocommerce' ); | |
break; | |
case 'grouped': | |
return __( 'View products', 'woocommerce' ); | |
break; | |
case 'simple': | |
return __( 'Add to cart', 'woocommerce' ); | |
break; | |
case 'variable': | |
return __( 'Select options', 'woocommerce' ); | |
break; | |
default: | |
return __( 'Read more', 'woocommerce' ); | |
} | |
} | |
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' ); | |
/*-------------------------------------------- | |
Product/SKU ID | |
---------------------------------------------*/ | |
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', 10); | |
// default sku id (single-product/meta.php) | |
function add_custom_sku(){ | |
global $product; | |
$sku = $product->get_sku(); | |
$sku_num = ($sku ? $sku : 'N/A'); | |
?> | |
<div class="custom-sku"> | |
<?php _e('<b>Product ID</b> : ', 'flipmart'); echo $sku_num; ?> | |
</div> | |
<?php | |
} | |
add_action('woocommerce_single_product_summary', 'add_custom_sku',6); | |
/*-------------------------------------------- | |
Stock Product abailability | |
---------------------------------------------*/ | |
add_action('woocommerce_single_product_summary', 'product_availbility', 38); | |
function product_availbility(){ | |
global $product; | |
$numleft = $product->get_stock_quantity(); | |
if($numleft==0) { | |
// out of stock | |
echo "<p style='font-style:italic;color:#DD4E42;margin-bottom:5px;'><b>Sorry, Out of stock.</b></p>"; | |
} | |
else if($numleft==1) { | |
echo '<span style="margin-bottom:5px;"><b>Availability</b> : '." Only ".$numleft ." item left.".'</span>'; | |
} | |
else if($numleft<10){ | |
echo '<span style="margin-bottom:5px;"><b>Availability</b> : '.$numleft ." items available in stock.".'</span>'; | |
} | |
else { | |
echo '<span style="margin-bottom:5px;"><b>Availability</b> : '.$numleft ." items left.".'</span>'; | |
} | |
} | |
/*-------------------------------------------- | |
Product shortdescription | |
---------------------------------------------*/ | |
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20); | |
function product_shortdescription(){ | |
?> | |
<div class="short-description"> | |
<p><?php the_excerpt(); ?></p> | |
</div> | |
<?php | |
} | |
add_action('woocommerce_single_product_summary', 'product_shortdescription',20); | |
/*--------------------------------------------------------- | |
single product page image er bottom gallrey image remove | |
----------------------------------------------------------*/ | |
//plugin/woocommerce/include/wc-template-hooks.php | |
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 ); | |
add_action('woocommerce_product_thumbnails','carousel_single_product'); | |
function carousel_single_product(){ | |
global $post, $product; | |
$attachment_ids = $product->get_gallery_image_ids(); | |
if($attachment_ids): | |
?> | |
<div class="product-image"> | |
<div class="flexslider flexslider-thumb"> | |
<div class="flex-viewport"> | |
<ul class="previews-list slides"> | |
<?php | |
$i=1; | |
foreach($attachment_ids as $attachment_id): | |
$image_link = wp_get_attachment_url($attachment_id); | |
?> | |
<li> | |
<a class="cloud-zoom-gallery" href="<?php echo $image_link; ?>"><img alt="Thumbnail 1" src="<?php echo $image_link; ?>" draggable="false"></a> | |
</li> | |
<?php $i++; endforeach; ?> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<?php | |
endif; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment