Home Forums Basel support forum Change the Translation of SALE button Reply To: Change the Translation of SALE button

#19491

Eric Watson
Participant

Hello,

Try to add the following code snippet to the functions.php file in the child theme and change your text.

function basel_product_label() {
	global $product;

	$output = array();

	if ( $product->is_on_sale() ) {

		$percentage = '';

		if ( $product->get_type() == 'variable' ) {

			$available_variations = $product->get_variation_prices();
			$max_percentage = 0;

			foreach( $available_variations['regular_price'] as $key => $regular_price ) {
				$sale_price = $available_variations['sale_price'][$key];

				if ( $sale_price < $regular_price ) {
					$percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );

					if ( $percentage > $max_percentage ) {
						$max_percentage = $percentage;
					}
				}
			}

			$percentage = $max_percentage;
		} elseif ( $product->get_type() == 'simple' || $product->get_type() == 'external' ) {
			$percentage = round( ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100 );
		}

		if ( $percentage && basel_get_opt( 'percentage_label' )  ) {
			$output[] = '<span class="onsale product-label">-' . $percentage . '%' . '</span>';
		}else{
			$output[] = '<span class="onsale product-label">' . esc_html__( 'Sale', 'woocommerce' ) . '</span>';
		}
	}elseif( ! $product->is_in_stock() && !is_product() ){
		$output[] = '<span class="out-of-stock product-label">' . esc_html__( 'Sold out', 'woocommerce' ) . '</span>';
	}

	if ( $product->is_featured() && basel_get_opt( 'hot_label' ) ) {
		$output[] = '<span class="featured product-label">' . esc_html__( 'Hot', 'basel' ) . '</span>';
	}
	if ( get_post_meta( get_the_ID(), '_basel_new_label', true ) && basel_get_opt( 'new_label' ) ) {
		$output[] = '<span class="new product-label">' . esc_html__( 'New', 'basel' ) . '</span>';
	}
	if ( $output ) {
		echo '<div class="product-labels labels-' . basel_get_opt( 'label_shape' ) . '">' . implode( '', $output ) . '</div>';
	}
}

Kind Regards
XTemos Studio