Professional Website Design at Your Budget | Call us - 01750-994707

Woocommerce All in one Customization Code

WooCommerce is a popular open-source e-commerce plugin for WordPress. It enables website owners to transform their WordPress websites into online stores. With WooCommerce, you can sell physical and digital products, manage inventory, handle payments, set up shipping options, and customize the look and functionality of your online store.

Sometimes need to change default things based on the need for client satisfaction. Here I will discuss with you the most frequent custom changes for woo commerce-powered online stores.

How to increase product variable limits?

If woocommerce variable comes with 50 product variations. If the product exceeded the limit of 50 then others will be not shown and the product variations tab. Now you need to increase the product variations limit.

Goto theme editor > theme function then paste this code at the bottom or above. This is increasing the product variations limit from 50 to 250 now. if you want to add more variations then replace the number with 250.

define( 'WC_MAX_LINKED_VARIATIONS', 250 );

Disclaimer: If you want more variations then you need to increase the memory limit from the PHP ini file. the huge number of variations will cause you to slow down your website and take time to finish the variation execution period.

WooCommerce variable products show only one price

 WordPress admin dashboard and Appearance> Theme editor > Function.php . Learn more about hiding variable products price on Woocommerce.

//Hide Price Range From for WooCommerce Variable Products by xdcoder.com

add_filter( 'woocommerce_variable_sale_price_html', 'lw_variable_product_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'lw_variable_product_price', 10, 2 );

function lw_variable_product_price( $v_price, $v_product ) {

    // Product Price
    $prod_prices = array( $v_product->get_variation_price( 'min', true ), 
                            $v_product->get_variation_price( 'max', true ) );
    $prod_price = $prod_prices[0] !== $prod_prices[1] ? wc_price( $prod_prices[0] ) : wc_price( $prod_prices[0] );

    // Regular Price
    $regular_prices = array( $v_product->get_variation_regular_price( 'min', true ), 
                          $v_product->get_variation_regular_price( 'max', true ) );
    sort( $regular_prices );
    $regular_price = $regular_prices[0] !== $regular_prices[1] ? wc_price( $regular_prices[0] ) : wc_price( $regular_prices[0] );

    if ( $prod_price !== $regular_price ) {
        $prod_price = '<del>' . $regular_price . $v_product->get_price_suffix() . '</del> <ins>' . 
                       $prod_price . $v_product->get_price_suffix() . '</ins>';
    }
    return $prod_price;
}

How to change any string or text in WordPress or Woocommerce

// change anytext in wordpress by XDCODER
add_filter( 'gettext', 'fs_translate_strings_1', 20, 3 );
function fs_translate_strings_1( $translation, $text, $domain ) {
	// STRING 1
	$translation = str_ireplace( 'My Old Text', 'My New Text', $translation );
	
	return $translation;
}

Leave a Comment