get_theme_mod( 'themefarmer_woocommerce_related_products_posts_per_page', 3),
'columns' => get_theme_mod( 'themefarmer_woocommerce_related_products_columns', 3),
);
$args = wp_parse_args( $defaults, $args );
return $args;
}
add_filter( 'woocommerce_output_related_products_args', 'newstore_woocommerce_related_products_args' );
if ( ! function_exists( 'newstore_woocommerce_product_columns_wrapper' ) ) {
/**
* Product columns wrapper.
*
* @return void
*/
function newstore_woocommerce_product_columns_wrapper() {
$columns = newstore_woocommerce_loop_columns();
echo '
';
}
}
add_action( 'woocommerce_before_shop_loop', 'newstore_woocommerce_product_columns_wrapper', 40 );
if ( ! function_exists( 'newstore_woocommerce_product_columns_wrapper_close' ) ) {
/**
* Product columns wrapper close.
*
* @return void
*/
function newstore_woocommerce_product_columns_wrapper_close() {
echo '
';
}
}
add_action( 'woocommerce_after_shop_loop', 'newstore_woocommerce_product_columns_wrapper_close', 40 );
/**
* Remove default WooCommerce wrapper.
*/
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
if ( ! function_exists( 'newstore_woocommerce_wrapper_before' ) ) {
/**
* Before Content.
*
* Wraps all WooCommerce content in wrappers which match the theme markup.
*
* @return void
*/
function newstore_woocommerce_wrapper_before() {
?>
*/
if ( ! function_exists( 'newstore_woocommerce_cart_link_fragment' ) ) {
/**
* Cart Fragments.
*
* Ensure cart contents update when products are added to the cart via AJAX.
*
* @param array $fragments Fragments to refresh via AJAX.
* @return array Fragments to refresh via AJAX.
*/
function newstore_woocommerce_cart_link_fragment( $fragments ) {
ob_start();
newstore_woocommerce_header_cart();
$fragments['.site-header-cart.woocommerce'] = ob_get_clean();
return $fragments;
}
}
add_filter( 'woocommerce_add_to_cart_fragments', 'newstore_woocommerce_cart_link_fragment' );
function newstore_tfwctool_wishlist_link(){
if (class_exists('TFWC_TOOL') && class_exists('TFWC_TOOL_Wishilst')) {
?>
wishlist->get_user_wishlist_products_count() ); ?>
';
echo wp_kses_post( get_the_term_list( $product->get_ID(), 'product_cat', '', ', ' ) );
echo '';
}
add_action( 'woocommerce_shop_loop_item_title', 'newstore_add_categories_before_title', 5);
// remove_action('woocommerce_after_shop_loop_item', 'TFWC_TOOL_Wishilst::add_to_wishlist_button', 30);
if(class_exists('TFWC_TOOL')){
if(class_exists('TFWC_TOOL_Wishilst')){
remove_action('woocommerce_after_shop_loop_item', 'tfwctool_add_to_wishlist_button', 30);
add_action('newstore_action_before_image_end', 'tfwctool_add_to_wishlist_button');
}
if(class_exists('TFWC_Tool_Quick_View')){
remove_action('woocommerce_after_shop_loop_item', 'tfwctool_quick_view_button', 20);
add_action('newstore_action_before_image_end', 'tfwctool_quick_view_button');
}
if(class_exists('TFWC_TOOL_Compare')){
remove_action('woocommerce_single_product_summary', 'tfwctool_add_to_compare_button', 35);
add_action('woocommerce_single_product_summary', 'tfwctool_add_to_compare_button', 999);
}
}
function newstore_woocommerce_sale_flash($sale_flash, $post, $product){
$sale_price = (float) $product->get_price();
$regular_price = (float) $product->get_regular_price();
$precision = 1;
if($sale_price < $regular_price){
$saving_percentage = round( 100 - ( $sale_price / $regular_price * 100 ), 1 ) . '%';
return '' . esc_html($saving_percentage) .' '.__('OFF', 'newstore').'';
}
return $sale_flash;
}
add_filter( 'woocommerce_sale_flash', 'newstore_woocommerce_sale_flash', 10, 3 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
function newstore_woocommerce_result_count_change_dropdown(){
$default_count = get_theme_mod( 'themefarmer_woocommerce_products_per_page', 12 );
$selected_count = isset($_REQUEST['count'])?intval($_REQUEST['count']):$default_count;
$product_count1 = intval($default_count);
$product_count2 = intval($default_count*2);
$product_count3 = intval($default_count*3);
$product_count4 = intval($default_count*4);
$product_count5 = intval($default_count*5);
?>
0 ){
$html = '' . wc_get_star_rating_html( $rating, $count ) . '
';
}else{
$html = '' . wc_get_star_rating_html( $rating, $count ) . '
';
}
return $html;
}
add_filter( 'woocommerce_product_get_rating_html', 'newstore_woocommerce_product_get_rating_html', 10, 3 );
function newstore_woocommerce_product_image_thumbs(){
global $product;
$attachment_ids = $product->get_gallery_image_ids();
if ( $attachment_ids && has_post_thumbnail() ) {
foreach ( $attachment_ids as $attachment_id ) {
$image = wp_get_attachment_image( $attachment_id, 'woocommerce_thumbnail', false, array(
'class' => 'wp-post-image tf-wc-loop-thumbs',
));
echo wp_kses_post( $image ).'
';
break;
}
}
}
add_action('woocommerce_before_shop_loop_item_title', 'newstore_woocommerce_product_image_thumbs', 10);
remove_action('woocommerce_after_shop_loop', 'woocommerce_pagination');
function newstore_woocommerce_pagination() {
?>
_wp_specialchars( get_post_field( 'post_title', $attachment_id ), ENT_QUOTES, 'UTF-8', true ),
'data-caption' => _wp_specialchars( get_post_field( 'post_excerpt', $attachment_id ), ENT_QUOTES, 'UTF-8', true ),
'data-src' => esc_url( $full_src[0] ),
'data-large_image' => esc_url( $full_src[0] ),
'data-large_image_width' => esc_attr( $full_src[1] ),
'data-large_image_height' => esc_attr( $full_src[2] ),
'class' => esc_attr( $main_image ? 'wp-post-image' : '' ),
),
$attachment_id,
$image_size,
$main_image
)
);
if($is_thumb){
return '' . $image . '
';
}else{
return '';
}
}
function newstore_get_page_labels() {
$lables = array(
'myaccount' => ' ' . __('My Account', 'newstore'),
'orders' => ''.__('My Orders', 'newstore'),
'details' => ''.__('Account details', 'newstore'),
'login' => ' ' . __('Login', 'newstore'),
'register' => ' ' . __('Register', 'newstore'),
'cart' => ' ' . __('Cart', 'newstore'),
'checkout' => ' ' . __('Checkout', 'newstore'),
'wishlist' => ' ' . __('Wishlist', 'newstore'),
'logout' => ' ' . __('Logout', 'newstore'),
);
$lables = apply_filters('newstore_page_labels', $lables);
return $lables;
}
function newstore_get_page_links_dropdown() {
if (class_exists('WooCommerce')) {
global $woocommerce;
$myaccount_page_id = get_option('woocommerce_myaccount_page_id');
$links = array();
$account_link = '#';
if ($myaccount_page_id) {
$account_link = get_permalink(absint($myaccount_page_id));
}
if (is_user_logged_in()) {
$links['myaccount'] = $account_link;
} else {
$links['login'] = $account_link;
$links['register'] = $account_link;
}
// $links['cart'] = wc_get_cart_url();
// $links['checkout'] = wc_get_checkout_url();
$wishlist_page_id = get_option('tfwctool_wishlist_page_id');
if($wishlist_page_id){
$links['wishlist'] = get_permalink(absint($wishlist_page_id));
}
if (is_user_logged_in()) {
$links['orders'] = wc_get_account_endpoint_url( 'orders' );
$links['details'] = wc_get_account_endpoint_url( 'edit-account' );
}
if (is_user_logged_in()) {
$links['logout'] = wp_logout_url(esc_url(home_url('/')));
if (get_option('woocommerce_force_ssl_checkout') == 'yes') {
$links['logout'] = str_replace('http:', 'https:', $links['logout']);
}
}
$links = apply_filters('newstore_page_links', $links);
$lables = newstore_get_page_labels();
$html = '';
foreach ($links as $key => $link) {
$html .= sprintf(' %3$s ',
esc_attr($key),
esc_url($link),
wp_kses_post($lables[$key])
);
}
$html = '
';
return $html;
}
}