Remove classes from wc_get_product_cat_class Woocommerce Function - woocommerce

The wc_get_product_cat_class function in Woocommerce wc-template-functions.php adds the classes 'first' and 'last' to some of my <li> elements.
I would like to remove those classes. Does anyone know how I can overwrite this in my functions.php without editing the actual Woocommerce functions?
I've searched everywhere but can't find any solutions. I'm still pretty new at this, hopefully this isn't too much of a dumbass question :/
Below is the function from wc-template-functions.php
function wc_get_product_cat_class( $class = '', $category = null ) {
global $woocommerce_loop;
$classes = is_array( $class ) ? $class : array_map( 'trim', explode( ' ', $class ) );
$classes[] = 'product-category';
$classes[] = 'product';
if ( 0 === ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 === $woocommerce_loop['columns'] ) {
$classes[] = 'first';
}
if ( 0 === $woocommerce_loop['loop'] % $woocommerce_loop['columns'] ) {
$classes[] = 'last';
}
$classes = apply_filters( 'product_cat_class', $classes, $class, $category );
return array_unique( array_filter( $classes ) );
}
And this is the code from content-product_cat.php template that calls the function
<li <?php wc_product_cat_class( '', $category ); ?>>
<?php
/**
* woocommerce_before_subcategory hook.
*
* #hooked woocommerce_template_loop_category_link_open - 10
*/
do_action( 'woocommerce_before_subcategory', $category );
/**
* woocommerce_before_subcategory_title hook.
*
* #hooked woocommerce_subcategory_thumbnail - 10
*/
do_action( 'woocommerce_before_subcategory_title', $category );
/**
* woocommerce_shop_loop_subcategory_title hook.
*
* #hooked woocommerce_template_loop_category_title - 10
*/
do_action( 'woocommerce_shop_loop_subcategory_title', $category );
/**
* woocommerce_after_subcategory_title hook.
*/
do_action( 'woocommerce_after_subcategory_title', $category );
/**
* woocommerce_after_subcategory hook.
*
* #hooked woocommerce_template_loop_category_link_close - 10
*/
do_action( 'woocommerce_after_subcategory', $category ); ?>
</li>

Delayed but thought this may help. You can define your own wc_product_cat_class function and call it from content-product_cat.php
For example:
If you want to remove the "first" and "last" class, you can use the code below.
function your_own_wc_product_cat_class( $class = '', $category = null ) {
$product_cat_classes = array_diff( wc_get_product_cat_class( $class, $category ), array( 'first', 'last' ) );
echo 'class="' . esc_attr( join( ' ', $product_cat_classes ) ) . '"';
}
Now you can call this from content-product_cat.php like this <?php ro_wc_product_cat_class() ?>

Maybe it's kinda too late but hopefully someone will need it too...
if ( ! function_exists( 'YOUR_product_cat_class' ) ) {
function YOUR_product_cat_class( $class = '', $category = null ) {
// this one is Toast grid based, I use it in my own theme
$classes[] = 'grid__col';
$wc_span = 12 / apply_filters( 'loop_shop_columns', 4 );
$spans = array( 6, 4, 3, 2 );
$span = in_array( $wc_span, $spans ) ? $wc_span : 4;
$classes[] = 'grid__col--' . $span . '-of-12';
return array_unique( array_filter( $classes ) );
}
}
add_filter( 'product_cat_class' , 'YOUR_product_cat_class' );
On a side note, be sure to edit your content-product_cat.php template properly. For instance, I don't use unordered list and my loop starts with DIV instead (content-product_cat.php, line #37):
<div <?php wc_product_cat_class( '', $category ); ?>>

Related

Need "Read More" button to show when excerpt field is filled out in wordpress

Need "Read More" button to show when excerpt field is filled out in wordpress. Currently the button only shows up when excerpt field is empty as it grabs the first paragraph of the post. I created a child theme. I think by changing this excerpt.php file from the parent theme may be the way to go but let me know...
<?php
if( ! function_exists( 'newslite_excerpt_length' ) ) :
/**
* Excerpt length
*
* #since newslite 1.0.0
*
* #param null
* #return int
*/
function newslite_excerpt_length( $length ){
global $newslite_customizer_all_values;
$excerpt_length = $newslite_customizer_all_values['newslite-excerpt-length'];
if ( empty( $excerpt_length) ) {
$excerpt_length = $length;
}
return absint( $excerpt_length );
}
endif;
add_filter( 'excerpt_length', 'newslite_excerpt_length', 999 );
if ( ! function_exists( 'newslite_implement_read_more' ) ) :
/**
* Implement read more in excerpt.
*
* #since 1.0.0
*
* #param string $more The string shown within the more link.
* #return string The excerpt.
*/
function newslite_implement_read_more( $more ) {
$flag_apply_excerpt_read_more = apply_filters( 'newslite_filter_excerpt_read_more', true );
if ( true !== $flag_apply_excerpt_read_more ) {
return $more;
}
$output = $more;
$read_more_text = __('continue reading','newslite');
if ( ! empty( $read_more_text ) ) {
$output = ' <div class="read-more-text">' . esc_html( $read_more_text ) . '</div>';
$output = apply_filters( 'newslite_filter_read_more_link' , $output );
}
return $output;
}
endif;
add_action( 'excerpt_more', 'newslite_implement_read_more' );

Edit Title Tag Wordpress tag.php

I'am trying to build an Input field for setting a custom HTML title-tag on tag.php in Wordpress. I archived it on page.php with custom fields. But it have no idea how to get it working on tag.php.
In My Function i have now:
add_theme_support( 'title-tag' );
add_filter( 'document_title_parts', 'orweb_custom_title');
function orweb_custom_title( $title ) {
if ( ! is_singular() ) return $title;
$custom_title = trim(get_post_meta( get_the_id(), 'title', true ));
if( ! empty( $custom_title ) ){
$custom_title = esc_html( $custom_title );
$title['title'] = $custom_title;
}
return $title;
}
function orweb_custom_title_old($title){
if ( ! is_singular() ) return;
$custom_title = trim(get_post_meta( get_the_id(), 'title', true));
if( ! empty( $custom_title ) ){
$custom_title = esc_html( $custom_title );
$title = $custom_title;
}
return $title;
}
add_filter('wp_title', 'orweb_custom_title_old', 10, 2);
Found here: https://orbitingweb.com/blog/custom-seo-friendly-title-tags-wordpress/.

How to get "items" column in orders panel in WooCommerce

Since WooCommerce major update 3.0+ the "Purchased" column in backend orders list panel has been removed. This column previously showed a toggle list of items in the order for quick viewing.
How to Get back this "items" column in orders panel?
If there is any hook for that? Any ideas?
Thanks
That appears to have been removed for performance reasons, but you could look at the code that was removed and add it back via the manage_shop_order_posts_columns filter and manage_shop_order_posts_custom_column action.
/**
* Modify the custom columns for orders.
* #param array $columns
* #return array
*/
function so_43719068_shop_order_columns( $columns ) {
// the new column as an array for subsequent array manip
$new_column = array( 'order_items' => __( 'Purchased', 'your-plugin' ) );
$insert_after = 'order_title';
// insert after specified column
if( isset( $columns[ $insert_after ] ) ){
// find the "title" column
$index = array_search( $insert_after, array_keys( $columns) );
// reform the array
$columns = array_merge( array_slice( $columns, 0, $index + 1, true ), $new_column, array_slice( $columns, $index, count( $columns ) - $index, true ) );
// or add to end
} else {
$columns = array_merge( $columns, $new_column );
}
return $columns;
}
add_filter( 'manage_shop_order_posts_columns', 'so_43719068_shop_order_columns', 20 );
/**
* Output custom columns for orders.
* #param string $column
* #param int $post_id
*/
function so_43719068_render_shop_order_columns( $column, $post_id ) {
global $the_order;
if ( empty( $the_order ) || $the_order->get_id() !== $post_id ) {
$the_order = wc_get_order( $post_id );
}
switch ( $column ) :
case 'order_items' :
/* translators: %d: order items count */
echo '' . apply_filters( 'woocommerce_admin_order_item_count', sprintf( _n( '%d item', '%d items', $the_order->get_item_count(), 'woocommerce' ), $the_order->get_item_count() ), $the_order ) . '';
if ( sizeof( $the_order->get_items() ) > 0 ) {
echo '<table class="show_order_items" cellspacing="0">';
foreach ( $the_order->get_items() as $item ) {
$product = apply_filters( 'woocommerce_order_item_product', $item->get_product(), $item );
$item_meta_html = wc_display_item_meta( $item, array( 'echo' => false ) );
?>
<tr class="<?php echo apply_filters( 'woocommerce_admin_order_item_class', '', $item, $the_order ); ?>">
<td class="qty"><?php echo esc_html( $item->get_quantity() ); ?></td>
<td class="name">
<?php if ( $product ) : ?>
<?php echo ( wc_product_sku_enabled() && $product->get_sku() ) ? $product->get_sku() . ' - ' : ''; ?><?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?>
<?php else : ?>
<?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?>
<?php endif; ?>
<?php if ( ! empty( $item_meta_html ) ) : ?>
<?php echo wc_help_tip( $item_meta_html ); ?>
<?php endif; ?>
</td>
</tr>
<?php
}
echo '</table>';
} else echo '–';
break;
endswitch;
}
add_action( 'manage_shop_order_posts_custom_column', 'so_43719068_render_shop_order_columns', 10, 2 );

Custom taxonomies won't display alphabetically

Is there anyone who knows why this is going on. Wordpress lists my custom taxonomies in the order they where inserted and not alphabetically. This is the code I'm using.
function get_the_term_list_inclusief( $id, $taxonomy, $before = '', $sep = '', $after = '') {
$terms = get_the_terms( $id, $taxonomy );
if ( is_wp_error( $terms ) )
return $terms;
if ( empty( $terms ) )
return false;
$links = array();
foreach ( $terms as $term ) {
$link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) ) {
return $link;
}
$links[] = '<a class="ajax" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
}
/**
* Filter the term links for a given taxonomy.
*
* The dynamic portion of the filter name, `$taxonomy`, refers
* to the taxonomy slug.
*
* #since 2.5.0
*
* #param array $links An array of term links.
*/
$term_links = apply_filters( "term_links-$taxonomy", $links );
return $before . join( $sep, $term_links ) . $after;
}
Is there away to use this code and have the taxonomies order by title or ASC?
Thanks
Try if this works:
// ...
$links = array();
usort($terms, function($a, $b) {
return strcmp($a->name, $b->name);
});
foreach ( $terms as $term ) {
// ...

WooCommerce product image zoom

I am currently working on a Wordpress website that supports WooCommerce. I've created a product, and I've uploaded a featured image and other photos for the gallery. But there is a problem i can't figure out. It doesn't matter how big the photo is, if I put the cursor on it, it zooms almost 200%, and that's too much. Does anyone know how to reduce (or remove) the zoom feature? I've been to "sinlge-product/product-image.php" but it seems I can't find any zoom option in the code:
<?php
/**
* Single Product Image
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.0.14
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $post, $woocommerce, $product;
?>
<div class="images">
<?php
if ( has_post_thumbnail() ) {
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image_caption = get_post( get_post_thumbnail_id() )->post_excerpt;
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
'title' => $image_title,
'alt' => $image_title
) );
$attachment_count = count( $product->get_gallery_attachment_ids() );
if ( $attachment_count > 0 ) {
$gallery = '[product-gallery]';
} else {
$gallery = '';
}
} else {
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="%s" />', wc_placeholder_img_src(), __( 'Placeholder', 'woocommerce' ) ), $post->ID );
}
?>
<?php do_action( 'woocommerce_product_thumbnails' ); ?>
</div>
Thank you!
Copy / Paste this code to functions.php on your child theme. Tested and approved ;)
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
add_filter( 'woocommerce_gallery_full_size', 'change_magnifier_lightbox_image_size', 20, 1 );
function change_magnifier_lightbox_image_size( $size ){
$thumbnail_id = get_post_thumbnail_id( get_the_id() );
$attachment = wp_get_attachment_metadata( $thumbnail_id, FALSE );
// Always return a value in a filter hook
return ( $attachment['width'] > 3071 || $attachment['height'] > 3071 ) ? 'preview' : 'large';
}

Resources