Generation

code to explanationFri, 03 Feb 2023

Que el peso pase de gr a kg con sus respectivos precios en woocommerce

function convert_weight_unit( $weight, $product ){ if( $weight == 0 ) return 0; $product_id = $product->get_id(); $base_unit = get_option( 'woocommerce_weight_unit' ); if( $base_unit == 'gr' ){ $multiplier = 0.001; } elseif( $base_unit == 'kg' ){ $multiplier = 1; } elseif( $base_unit == 'lbs' ){ $multiplier = 0.453592; } elseif( $base_unit == 'oz' ){ $multiplier = 0.0283495; } else { return $weight; } $new_unit_weight = $weight * $multiplier; update_post_meta( $product_id, '_weight', $new_unit_weight ); return $new_unit_weight; } add_filter( 'woocommerce_product_get

Want to kickstart your project?Use the new AI Studio to create your code