is_in_stock() ) { esc_html( sprintf( apply_filters( 'bloglo_woocommerce_out_of_stock_badge', sprintf( '%s', esc_html__( 'Sold Out', 'bloglo' ) ) ) ) ); } } endif; if ( ! function_exists( 'bloglo_wc_add_percentage_to_sale_badge' ) ) : /** * Outputs badge with percentage discount for product. * * @since 1.0.0 * @param string $html Cart widget content. * @param object $post Post object. * @param object $product Product object. */ function bloglo_wc_add_percentage_to_sale_badge( $html, $post, $product ) { $badge = bloglo_option( 'product_sale_badge' ); if ( 'hide' === $badge ) { return ''; } if ( ! $product->is_in_stock() && ! $product->backorders_allowed() ) { return ''; } $text = ''; if ( 'text' === $badge ) { $text = bloglo_option( 'product_sale_badge_text' ); } elseif ( 'percentage' === $badge ) { if ( $product->is_type( 'variable' ) ) { $percentages = array(); // Get all variation prices. $prices = $product->get_variation_prices(); // Loop through variation prices. foreach ( $prices['price'] as $key => $price ) { // Only on sale variations. if ( $prices['regular_price'][ $key ] !== $price ) { // Prevent dividing by 0. if ( ! $prices['regular_price'][ $key ] ) { return $html; } // Calculate and set in the array the percentage for each variation on sale. $percentages[] = round( 100 - ( $prices['sale_price'][ $key ] / $prices['regular_price'][ $key ] * 100 ) ); } } // We keep the highest value. $text = '-' . max( $percentages ) . '%'; } else { $regular_price = (float) $product->get_regular_price(); $sale_price = (float) $product->get_sale_price(); // Prevent dividing by 0. if ( ! $regular_price ) { return $html; } $text = '-' . round( 100 - ( $sale_price / $regular_price * 100 ) ) . '%'; } } return $text || is_customize_preview() ? '' . esc_html( $text ) . '' : ''; } endif; if ( ! function_exists( 'bloglo_wc_empty_cart_button' ) ) : /** * Add empty cart - button to return to cart page. * * @since 1.0.0 */ function bloglo_wc_empty_cart_button() { if ( ! wc_get_page_id( 'shop' ) ) { return; } ?>
', $output ); $output = str_replace( ')', '', $output ); return $output; } endif; if ( ! function_exists( 'bloglo_wc_cat_count_filter' ) ) : /** * Filters product category subtitle (count). * * @since 1.0.0 * * @param string $output The count output. * @param array $category The category. * @return string */ function bloglo_wc_cat_count_filter( $output, $category ) { $count = $category->count; /* translators: %s is category count */ $text = sprintf( _n( '%s product', '%s products', $count, 'bloglo' ), $count ); return '' . esc_html( $text ) . ''; } endif;