Error in result-count.php
-
This theme wasn’t updated for the latest version of WooCommerce that came out recently. I was getting an error in result-count.php. WooCommerce changed the way that it passes certain values. I used the following code to fix the issue.
<?php
/**
* Result Count
*
* Updated for WooCommerce 7.8+.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// WooCommerce now passes values inside $args.
$total = isset( $args['total'] ) ? (int) $args['total'] : 0;
$per_page = isset( $args['per_page'] ) ? (int) $args['per_page'] : 0;
$current = isset( $args['current'] ) ? (int) $args['current'] : 1;
?>
<div class="woocommerce-result-count-wrapper woostify-result-count-wrapper" itemscope itemtype="https://schema.org/ItemList">
<meta itemprop="numberOfItems" content="<?php echo esc_attr( $total ); ?>" />
<meta itemprop="itemListOrder" content="https://schema.org/ItemListOrderAscending" />
<p class="woocommerce-result-count woostify-result-count text-sm md:text-base" aria-live="polite">
<?php
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
if ( 1 === $total ) {
_e( 'Showing the single result', 'woostify' );
} elseif ( $total <= $per_page || -1 === $per_page ) {
printf(
_n(
'Showing all %d result',
'Showing all %d results',
$total,
'woostify'
),
$total
);
} else {
$first = ( $per_page * $current ) - $per_page + 1;
$last = min( $total, $per_page * $current );
printf(
_nx(
'Showing <span class="result-first" itemprop="startIndex">%1$d</span>–<span class="result-end" itemprop="endIndex">%2$d</span> of <span class="result-total" itemprop="numberOfItems">%3$d</span> result',
'Showing <span class="result-first" itemprop="startIndex">%1$d</span>–<span class="result-end" itemprop="endIndex">%2$d</span> of <span class="result-total" itemprop="numberOfItems">%3$d</span> results',
$total,
'with first and last result',
'woostify'
),
$first,
$last,
$total
);
}
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</p>
</div>
You must be logged in to reply to this topic.
