Skip to content

Instantly share code, notes, and snippets.

View rynaldos-zz's full-sized avatar

Rynaldo rynaldos-zz

View GitHub Profile
/**
* Force VAT field to be filled
*/
add_action('woocommerce_checkout_process', 'wc_force_vat_field_to_be_not_empty');
function wc_force_vat_field_to_be_not_empty() {
global $woocommerce;
// Check if set, if its not set add an error.
if( $woocommerce->customer->get_country() != 'SE' ) {
function woo_ninja_remove_price_range( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( '%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 );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
@rynaldos-zz
rynaldos-zz / nopricerange-from.php
Created January 27, 2016 14:18
remove price range and add prepending text to base price
function woo_ninja_remove_price_range( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( '%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 );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
@rynaldos-zz
rynaldos-zz / localize-datepicker.php
Created February 18, 2016 11:24
Localizing jQuery UI Datepicker
add_filter( 'wp_footer' , 'rc_localize_datepicker' );
/**
* Localize datepicker fields
*
* @access public
* @since 1.0
* @return void
*/
function rc_localize_datepicker() {
@rynaldos-zz
rynaldos-zz / wc-make-vat-required.php
Last active March 24, 2017 11:18
[WooCommerce] Make the EU-VAT field required during checkout (and add asterisk)
add_action('woocommerce_checkout_process', 'wc_force_vat_field_to_be_not_empty');
function wc_force_vat_field_to_be_not_empty() {
// Check if set, if its not set add an error.
if ( ! $_POST['vat_number']);
wc_add_notice( __( 'Please enter your VAT number.' ), 'error' );
}
// adding the asterisk (css)
@rynaldos-zz
rynaldos-zz / wc-eu-vat-select-countries.php
Last active February 3, 2017 08:37
[WooCommerce] Make the VAT field required for select countries
add_action('woocommerce_checkout_process', 'wc_force_vat_field_to_be_not_empty');
function wc_force_vat_field_to_be_not_empty() {
global $woocommerce;
// Define countries where VAT field is mandatory
$eu_countries = array('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SI', 'SK');
// Check if customer is in one of those countries
if( in_array( $woocommerce->customer->get_country(), $eu_countries ) ) {
@rynaldos-zz
rynaldos-zz / disable-jp-inf-scroll-cond.php
Last active February 3, 2017 08:35
[WordPress ] Disable Jetpack's Infinite scroll (conditionally)
function _rsp_disable_jetpack_infinite_scroll_conditionally() {
if ( true === my_conditionals() ) {
remove_theme_support( 'infinite-scroll' );
}
}
add_action( 'template_redirect', '_rsp_disable_jetpack_infinite_scroll_conditionally', 9 );
@rynaldos-zz
rynaldos-zz / wc-remove-var-price-range.php
Last active February 3, 2017 08:34
[WooCommerce] Removes the price range from variable products
function woo_ninja_remove_price_range( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( '%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 );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
@rynaldos-zz
rynaldos-zz / wc-usd-us-append
Last active February 3, 2017 08:29
[WooCommerce] Prepends the country code (US) to $ currency
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'USD': $currency_symbol = 'US$'; break;
}
return $currency_symbol;
}
@rynaldos-zz
rynaldos-zz / cnorp.php
Created May 9, 2016 18:25
Change number of related products
function woo_related_products_limit() {
global $product;
$args['posts_per_page'] = 6;
return $args;
}
add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args' );
function jk_related_products_args( $args ) {
$args['posts_per_page'] = 6; // 4 related products
$args['columns'] = 3; // arranged in 2 columns