Home › Forums › WoodMart support forum › Variation Swatches is not visible on Variable Raw Products › Reply To: Variation Swatches is not visible on Variable Raw Products
k9casual.com
Hi ,
Thanks for the quick support; my point is that this atum plugin one more product type in addition to default product types; which is “simple raw product and variable raw product”. It may be reason that swatches are available only for default products types.
So my concern is that can we add this new product type in code of woodmart swatches function; if this happens then swatches will be also visible for raw product types.
I fixed the same type of error for saving display in a single product page, pls check below custom code:-
add_action( ‘woocommerce_single_product_summary’, ‘cssigniter_woocommerce_get_product_sale_savings’, 11 );
/**
* Returns a textual string with the amount saved for on-sale products.
*
* Compound products, such as grouped and variable products, may have multiple different savings amounts due to
* on-sale children products or variations. In these cases, both ‘min’ and ‘max’ values are set, although may be the same.
*
* @return string
*/
function cssigniter_woocommerce_get_product_sale_savings() {
global $product;
if ( ! $product->is_on_sale() ) {
return;
}
$savings = array(
‘min’ => false,
‘max’ => false,
);
$savings_html = ”;
switch ( $product->get_type() ) {
case ‘grouped’:
$children = array_filter( array_map( ‘wc_get_product’, $product->get_children() ), ‘wc_products_array_filter_visible_grouped’ );
foreach ( $children as $child ) {
if ( $child->is_purchasable() && ! $child->is_type( ‘grouped’ ) && $child->is_on_sale() ) {
$child_regular_price = (float) wc_get_price_to_display( $child, array( ‘price’ => $child->get_regular_price() ) );
$child_active_price = (float) wc_get_price_to_display( $child, array( ‘price’ => $child->get_sale_price() ) );
$child_savings = $child_regular_price – $child_active_price;
$savings[‘min’] = false !== $savings[‘min’] ? $savings[‘min’] : $child_savings;
$savings[‘max’] = false !== $savings[‘max’] ? $savings[‘max’] : $child_savings;
if ( $child_savings < $savings[‘min’] ) {
$savings[‘min’] = $child_savings;
}
if ( $child_savings > $savings[‘max’] ) {
$savings[‘max’] = $child_savings;
}
}
}
break;
case ‘variable’:
$prices = $product->get_variation_prices();
foreach ( $prices[‘price’] as $variation_id => $price ) {
$regular_price = (float) $prices[‘regular_price’][ $variation_id ];
$sale_price = (float) $prices[‘sale_price’][ $variation_id ];
if ( $sale_price < $regular_price ) {
$variation_savings = $regular_price – $sale_price;
$savings[‘min’] = false !== $savings[‘min’] ? $savings[‘min’] : $variation_savings;
$savings[‘max’] = false !== $savings[‘max’] ? $savings[‘max’] : $variation_savings;
if ( $variation_savings < $savings[‘min’] ) {
$savings[‘min’] = $variation_savings;
}
if ( $variation_savings > $savings[‘max’] ) {
$savings[‘max’] = $variation_savings;
}
}
}
break;
case ‘variable-raw-material’:
$prices = $product->get_variation_prices();
foreach ( $prices[‘price’] as $variation_id => $price ) {
$regular_price = (float) $prices[‘regular_price’][ $variation_id ];
$sale_price = (float) $prices[‘sale_price’][ $variation_id ];
if ( $sale_price < $regular_price ) {
$variation_savings = $regular_price – $sale_price;
$savings[‘min’] = false !== $savings[‘min’] ? $savings[‘min’] : $variation_savings;
$savings[‘max’] = false !== $savings[‘max’] ? $savings[‘max’] : $variation_savings;
if ( $variation_savings < $savings[‘min’] ) {
$savings[‘min’] = $variation_savings;
}
if ( $variation_savings > $savings[‘max’] ) {
$savings[‘max’] = $variation_savings;
}
}
}
break;
case ‘external’:
case ‘variation’:
case ‘simple’:
case ‘variable-raw-material’:
default:
$regular_price = (float) $product->get_regular_price();
$sale_price = (float) $product->get_sale_price();
if ( $sale_price < $regular_price ) {
$savings[‘max’] = $regular_price – $sale_price;
}
}
if ( ! empty( $savings[‘min’] ) ) {
$savings_html = ‘<p class=”woocommerce-message”>’ . __( ‘Save ‘, ‘your-text-domain’ ) . ‘ up to ‘ . wc_price( $savings[‘max’] ) . ‘ ‘ . __( ‘per item.’, ‘your-text-domain’ ) . ‘</p>’;
} else {
$savings_html = ‘<p class=”woocommerce-message”>’ . __( ‘You save ‘, ‘your-text-domain’ ) . wc_price( $savings[‘max’] ) . ‘</p>’;
}
echo wp_kses_post( $savings_html );
/*$savings_html = ‘<p class=”woocommerce-message”>’ . __( ‘Save from ‘, ‘your-text-domain’ ) . wc_price( $savings[‘min’] ) . ‘ up to ‘ . wc_price( $savings[‘max’] ) . ‘ ‘ . __( ‘per item.’, ‘your-text-domain’ ) . ‘</p>’;*/
}
regards