Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Nota › Sales badge in percent
New Landing › How can we help? › Themeforest Theme Support › Nota › Sales badge in percent
- This topic has 4 replies, 3 voices, and was last updated 7 years by David Martin – Support.
Viewing 5 posts - 1 through 5 (of 5 total)
-
Posted in: Nota
-
January 9, 2017 at 4:12 pm #309323
Hey,
wanna know how to replace the sale badge on nota theme to show sale in percent instead of “Sale”.
If you have a solution can you tell me :).
Thanks for your support.
January 9, 2017 at 4:51 pm #309330Please install and activate the supplied child theme, inside the child theme
functions.php
file paste this:if ( ! function_exists( 'sf_product_get_sale_percent' ) ) { function sf_product_get_sale_percent( $product ) { global $product; if ( $product->product_type === 'variable' ) { $product_variation_prices = $product->get_variation_prices(); $highest_sale_percent = 0; foreach( $product_variation_prices['regular_price'] as $key => $regular_price ) { $sale_price = $product_variation_prices['sale_price'][$key]; if ( $sale_price < $regular_price ) { $sale_percent = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 ); if ( $sale_percent > $highest_sale_percent ) { $highest_sale_percent = $sale_percent; } } } return $highest_sale_percent; } else { $sale_percent = 0; if ( intval( $product->regular_price ) > 0 ) { $sale_percent = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 ); } return $sale_percent; } } } /* PRODUCT BADGE ================================================== */ if ( ! function_exists( 'nota_woo_product_badge' ) ) { function nota_woo_product_badge() { global $product, $post; $nota_options = nota_get_theme_opts(); $postdate = get_the_time( 'Y-m-d' ); // Post date $postdatestamp = strtotime( $postdate ); // Timestamped post date $newness = $nota_options['new_badge']; // Newness in days $extra_class = $out = ""; $percentage_off = sf_product_get_sale_percent( $product->id ); if ( nota_is_out_of_stock() || $product->is_on_sale() || ( time() - ( 60 * 60 * 24 * $newness ) ) < $postdatestamp || $product->get_price() != "" && $product->get_price() == 0 ) { if ( nota_is_out_of_stock() ) { $out .= '<span class="out-of-stock-badge">' . esc_html__( 'Sold out', 'nota' ) . '</span>'; $extra_class = "sf-out-of-stock"; } else if ( $product->is_on_sale() ) { $out .= apply_filters('woocommerce_sale_flash', '<span class="onsale">—' . $percentage_off . ''.esc_html__('%', 'nota' ).'</span>', $post, $product); $extra_class = "sf-on-sale"; } else if ( ( time() - ( 60 * 60 * 24 * $newness ) ) < $postdatestamp ) { // If the product was published within the newness time frame display the new badge $out .= '<span class="wc-new-badge">' . esc_html__( 'New', 'nota' ) . '</span>'; $extra_class = "sf-new-stock"; } else if ( $product->get_price() != "" && $product->get_price() == 0 ) { $out .= '<span class="free-badge">' . esc_html__( 'Free', 'nota' ) . '</span>'; $extra_class = "sf-free-stock"; } echo '<div class="badge-wrap ' . esc_attr( $extra_class ) . '">' . $out; echo '</div>'; } } }
January 9, 2017 at 7:55 pm #309348YESS ! Always a good support, thanks a lot :=)
January 9, 2017 at 8:13 pm #309350Great. Thanks David.
-Rui
January 10, 2017 at 2:34 pm #309475If you have found the theme/support useful, we appreciate it if you can leave feedback on our item if you have the time as it really helps us out.
Cheers.
-
Posted in: Nota
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in and have valid license to reply to this topic.