New Landing How can we help? Themeforest Theme Support Nota Sales badge in percent

Viewing 5 posts - 1 through 5 (of 5 total)
  • Posted in: Nota
  • #309323
    Stonedb
    Member
    Post count: 34

    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.

    #309330
    David Martin – Support
    Moderator
    Post count: 20834

    Please 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">&mdash;' . $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>';
    	    	}
    	   }
    	}
    #309348
    Stonedb
    Member
    Post count: 34

    YESS ! Always a good support, thanks a lot :=)

    #309350
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Great. Thanks David.

    -Rui

    #309475
    David Martin – Support
    Moderator
    Post count: 20834

    If 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.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register