term_id; endif; $sideproducts = alanah_get_option( 'side_products' ); $sideproductnum = ( alanah_get_option( 'numberofproducts' ) ) ? alanah_get_option( 'numberofproducts' ) : 3; $discount_badge = alanah_get_option( 'side_products_discount' ); $buynow = alanah_get_option( 'side_products_buynow' ); $buynow_text = ( alanah_get_option( 'buynow_text' ) ) ? alanah_get_option( 'buynow_text' ) : __( 'Buy Now', 'alanah-free' ); ?>
'product', 'numberposts' => $sideproductnum, 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $sideproductcat, 'operator' => 'IN' ) ) ); if( alanah_get_option( 'side_products_random' ) ) { $args['orderby'] = 'rand'; $args['order'] = 'ASC'; } $products = get_posts( $args ); if( !empty( $products ) ) : foreach( $products as $product ) { $item = wc_get_product( $product->ID ); $image = wp_get_attachment_image_url( get_post_thumbnail_id( $item->get_id() ), 'single-post-thumbnail' ); ?>
get_sale_price() > 0 ) : if( $item->is_type( 'variable' ) ) { $percentages = array(); // Get all variation prices $prices = $item->get_variation_prices(); // Loop through variation prices foreach( $prices['price'] as $key => $price ) { // Only on sale variations if( $prices['regular_price'][$key] !== $price ) : // 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 ) ); endif; } $percentage = max( $percentages ) . '%'; } else { $regular_price = (float) $item->get_regular_price(); $sale_price = (float) $item->get_sale_price(); $percentage = round(100 - ( $sale_price / $regular_price * 100 ) ) . '%'; } ?>