Categories
WooCommerce

WooCommerce Variation Price instead Range

And the New Zealand Bird.

Display the variation price instead of the range:

function get_default_variation( $product ) {
	// If no default variation exist we exit
	if ( count( $product->get_variation_attributes() ) != count( $product->get_default_attributes() ) )
        	return false;
	foreach( $product->get_available_variations() as $variation ) {
		$found = true;
		foreach( $variation['attributes'] as $key => $value ) {
			$taxonomy = str_replace( 'attribute_', '', $key );
			// Searching for a matching variation as default
			if ( isset( $default_attributes[$taxonomy] ) && $default_attributes[$taxonomy] != $value ) {
				$found = false;
				break;
			}
		}
		if ( $found ) {
			$default_variaton = $variation;
			break;
		}
		else {
			continue;
		}
	}
	return isset($default_variaton) ? $default_variaton : false;
}

add_action( 'woocommerce_before_single_product', 'condless_move_variations_single_price', 1 );
function condless_move_variations_single_price() {
	global $product, $post;
	if ( $product->is_type( 'variable' ) ) {
		// Removing the variations price for variable products
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' );
		// Change location and inserting back the variations price
		add_action( 'woocommerce_single_product_summary', 'condless_replace_variation_single_price' );
	}
}

function condless_replace_variation_single_price() {
	global $product;
	// Main Price
	$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
	$active_price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

	// Sale Price
	$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
	sort( $prices );
	$regular_price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

	if ( $active_price !== $regular_price && $product->is_on_sale() ) {
		$price = '<del>' . $regular_price . $product->get_price_suffix() . '</del> <ins>' . $active_price . $product->get_price_suffix() . '</ins>';
	} else {
		$price = $regular_price;
	}

	// When a default variation is set for the variable product
	if ( get_default_variation( $product ) ) {
	$default_variaton = get_default_variation( $product );
	if ( ! empty( $default_variaton['price_html'] ) ) {
		$price_html = $default_variaton['price_html'];
	} else {
		if ( ! $product->is_on_sale() )
			$price_html = $price = wc_price( $default_variaton['display_price'] );
		else
			$price_html = $price;
	}
	$availiability = $default_variaton['availability_html'];
	} else {
		$price_html = $price;
		$availiability = '';
	}
	// Styles ?>
	<style>
	div.woocommerce-variation-price,
	div.woocommerce-variation-availability,
	div.hidden-variable-price {
		height: 0px !important;
		overflow:hidden;
		position:relative;
		line-height: 0px !important;
		font-size: 0% !important;
	}
	</style>
	<?php // Jquery ?>
	<script>
	jQuery(document).ready(function($) {
		var a = 'div.wc-availability', p = 'p.price';
		$('input.variation_id').change( function() {
			if ( '' != $('input.variation_id').val() ) {
				if ($(a).html() != '' ) $(a).html('');
		$(p).html($('div.woocommerce-variation-price > span.price').html());
		$(a).html($('div.woocommerce-variation-availability').html());
		} else {
			if ($(a).html() != '' ) $(a).html('');
			$(p).html($('div.hidden-variable-price').html());
		}
		});
	});
	</script>
	<?php
	echo '<p class="price">'.$price_html.'</p>
	<div class="wc-availability">'.$availiability.'</div>
	<div class="hidden-variable-price" >'.$price.'</div>';
}

add_filter( 'woocommerce_variable_price_html', 'condless_variation_price_format', 10, 2 );
function condless_variation_price_format( $price, $product ) {
	if ( is_shop() ) {
		$min_var_reg_price = $product->get_variation_regular_price( 'min', true );
		$min_var_sale_price = $product->get_variation_sale_price( 'min', true );
		$max_var_reg_price = $product->get_variation_regular_price( 'max', true );
		$max_var_sale_price = $product->get_variation_sale_price( 'max', true );
		if ( ! ( $min_var_reg_price == $max_var_reg_price && $min_var_sale_price == $max_var_sale_price ) ) {
			if ( $min_var_sale_price < $min_var_reg_price ) {
				$price = sprintf( __( 'From: <del>%1$s</del><ins>%2$s</ins>', 'woocommerce' ), wc_price( $min_var_reg_price ), wc_price( $min_var_sale_price ) );
			} else {
				$price = sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $min_var_reg_price ) );
			}
		}
	}
	return $price;
}

As you probably have noticed- the prices in auctions can surprise even the seller, as was the sale of a single feather from extinct Huia bird in the early 20th century, which sold for $10,000.

Categories
WooCommerce

WooCommerce Tax

And Pharaoh.

Display the VAT amount in separate line in the cart/checkout pages (relevant when display prices include taxes is configured):

add_action( 'woocommerce_cart_totals_before_order_total', 'condless_wc_display_vat' );
add_action( 'woocommerce_review_order_before_order_total', 'condless_wc_display_vat' );
function condless_wc_display_vat() {
        foreach( WC()->cart->get_taxes() as $tax ) $all_tax += $tax;
        echo '<tr class="cart-discount">
        <th>'. __( esc_attr( WC()->countries->tax_or_vat() ), 'woocommerce' ) .'</th>
        <td data-title=" '. __( esc_attr( WC()->countries->tax_or_vat() ), 'woocommerce' ) .' ">' . wc_price ( $all_tax ) .'</td>
        </tr>';
}

add_filter( 'woocommerce_cart_totals_order_total_html', 'condless_cart_totals_order_total_html' );
function condless_cart_totals_order_total_html( $value ) {
        $value = '<strong>' . WC()->cart->get_total() . '</strong> ';
        return $value;
}

Config fixed products’ prices regardless of the buyers’ country VAT (choose in settings that prices include tax was inserted):

add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false' );

As you probably have noticed- the first known taxation system was in Ancient Egypt, the ruler used to do bi-annual trips to collect taxes.

Categories
WooCommerce

WooCommerce Sell Media

And The University of the People.

Sell access to digital media (content pages, video courses, images, music):

  • Create virtual product with direct link for each item
  • Restrict the items that only those who purchased the compatible product may access it with the plugin
  • Enable content protection with the plugin
  • Limit connection to only one device with the plugin
  • Activate Two-factor authentication

As you probably have noticed- distance learning occupies a growing part of the way of learning, the one that has taken it one step further, is the University of the People, which does not have a physical campus and offers a full online degree without tuition.