get_type(); $is_on_sale = $product->is_on_sale(); if ( ! $is_on_sale ) { return false; } if ( 'variable' == $product_type ) { $prices = $product->get_variation_prices(); foreach ( $prices['price'] as $key => $price ) { // Only on sale variations if ( $prices['regular_price'][ $key ] !== $price ) { $percentages[] = round( 100 - ( floatval( $prices['sale_price'][ $key ] ) / floatval( $prices['regular_price'][ $key ] ) * 100 ) ); } } // Keep the highest value $percentage = max( $percentages ) . '%'; } elseif ( 'grouped' == $product_type ) { $children_ids = $product->get_children(); foreach ( $children_ids as $child_id ) { $child_product = wc_get_product( $child_id ); $regular_price = (float) $child_product->get_regular_price(); $sale_price = (float) $child_product->get_sale_price(); if ( $sale_price != 0 || ! empty( $sale_price ) ) { $percentages[] = round( 100 - ( $sale_price / $regular_price * 100 ) ); } } // Keep the highest value $percentage = max( $percentages ) . '%'; } else { $regular_price = (float) $product->get_regular_price(); $sale_price = (float) $product->get_sale_price(); if ( $sale_price != 0 || ! empty( $sale_price ) ) { $percentage = round( 100 - ( $sale_price / $regular_price * 100 ) ) . '%'; } else { return false; } } return printf( '%s%s', absint( $percentage ), esc_html__( '% OFF', 'beetan' ) ); } } if ( ! function_exists( 'beetan_product_brand' ) ) { function beetan_product_brand() { $brand_obj = wp_get_object_terms( get_the_ID(), 'product_brand' ); if ( ! empty( $brand_obj ) ) { $brand_array = wp_list_pluck( $brand_obj, 'name' ); $brand_name = implode( ',', $brand_array ); echo '' . esc_html( $brand_name ) . ''; } } } if ( class_exists( 'Woo_Variation_Gallery' ) ) { /** * Additional Variation Image Gallery plugin compatible */ add_filter( 'woo_variation_gallery_default_width', function ( $width ) { $width = 48; return $width; } ); } if ( ! function_exists( 'beetan_shop_product_title' ) ) { /** * Shop product title */ function beetan_shop_product_title() { echo ''; woocommerce_template_loop_product_title(); echo ''; } } if ( ! function_exists( 'beetan_shop_product_img_overlay' ) ) { /** * Shop thumbnail overlay */ function beetan_shop_product_img_overlay() { echo '
'; } } if ( ! function_exists( 'beetan_shop_item_view_details_button' ) ) { /** * Shop view details button */ function beetan_shop_item_view_details_button() { printf( '%s', esc_url( get_the_permalink() ), esc_html__( 'View Details', 'beetan' ) ); } } if ( ! function_exists( 'beetan_change_shop_pagination_arrow' ) ) { /** * Change shop page pagination arrow * * @param $args * * @return mixed */ function beetan_change_shop_pagination_arrow( $args ) { $args['prev_text'] = ''; $args['next_text'] = ''; return $args; } } add_filter( 'woocommerce_pagination_args', 'beetan_change_shop_pagination_arrow' );