I think this might help you achieve your goal.
At the end of the functions.php
file, add the following PHP code:
// Add custom price calculation for WooCommerce products
add_filter('woocommerce_get_price_html', 'custom_product_price_html', 10, 2);
function custom_product_price_html($price_html, $product) {
if ($product->is_type('simple')) {
// Get the product price
$product_price = floatval($product->get_price());
// Get the attribute value (partial_payments)
$attribute_value = intval($product->get_attribute('partial_payments'));
if ($attribute_value > 0) {
// Calculate the new price
$new_price = $product_price / $attribute_value;
// Format the new price
$new_price_html = wc_price($new_price);
// Display the new price with the attribute value
$price_html = sprintf('%dx%s', $attribute_value, $new_price_html);
}
}
return $price_html;
}
Now, your custom price calculation code will dynamically calculate and display the new prices based on the “partial_payments” attribute value for your WooCommerce products. Make sure to replace “partial_payments” with the actual slug of your attribute.
Remember to create a backup of your site or the functions.php
file before making any changes to ensure you can revert them if needed!