Skip to main content
Articles

WooCommerce Hacking The Price Field With get_sku()

This is actually really handy for when you have variable options and WooCommerce just echos out a $0 dollar amount on the product page until something is selected as an option in the product itself. This way you can set a default starting price that doesn’t affect the cart math.

MCC Cart Math



add_filter( 'woocommerce_get_price_html', 'wally_price_free_empty', 9999, 2 );
   
function wally_price_free_empty( $price, $product ){
    if ( '' === $product->get_sku() || 6100 == $product->get_sku() ) {
        $price = '<span class="woocommerce-Price-amount amount">Starting at $34.00</span>';
    }  
    return $price;
}

add_filter( 'woocommerce_get_price_html', 'wally_price_free_empty2', 9999, 2 );

function wally_price_free_empty2( $price, $product ){
    if ( '' === $product->get_sku() || 61002 == $product->get_sku() ) {
        $price = '<span class="woocommerce-Price-amount amount">Starting at $34.00</span>';
    }  
    return $price;
}

add_filter( 'woocommerce_get_price_html', 'wally_price_free_empty3', 9999, 2 );

function wally_price_free_empty3( $price, $product ){
    if ( '' === $product->get_sku() || 6001 == $product->get_sku() ) {
        $price = '<span class="woocommerce-Price-amount amount">Starting at $20.00</span>';
    }  
    return $price;
}

add_filter( 'woocommerce_get_price_html', 'wally_price_free_empty4', 9999, 2 );

function wally_price_free_empty4( $price, $product ){
    if ( '' === $product->get_sku() || 60012 == $product->get_sku() ) {
        $price = '<span class="woocommerce-Price-amount amount">Starting at $20.00</span>';
    }  
    return $price;
}

add_filter( 'woocommerce_get_price_html', 'wally_price_free_empty5', 9999, 2 );

function wally_price_free_empty5( $price, $product ){
    if ( '' === $product->get_sku() || 106 == $product->get_sku() ) {
        $price = '<span class="woocommerce-Price-amount amount">Starting at $20.00</span>';
    }  
    return $price;
}

add_filter( 'woocommerce_get_price_html', 'wally_price_free_empty6', 9999, 2 );

function wally_price_free_empty6( $price, $product ){
    if ( '' === $product->get_sku() || 1062 == $product->get_sku() ) {
        $price = '<span class="woocommerce-Price-amount amount">Starting at $20.00</span>';
    }  
    return $price;
}