Pyöristä hinnat
unknown
php
a year ago
817 B
97
Indexable
function adjust_and_round_prices() {
// Hae kaikki tuotteet
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
);
$products = get_posts($args);
foreach ($products as $product) {
// Lataa tuote-objekti
$product_obj = wc_get_product($product->ID);
// Hae nykyinen hinta
$regular_price = $product_obj->get_regular_price();
// Nosta hintaa 1.5%
$new_price = $regular_price * 1.015;
// Pyöristä hinta yhteen desimaaliin ylöspäin
$rounded_price = ceil($new_price * 10) / 10;
// Aseta uusi hinta
$product_obj->set_regular_price($rounded_price);
$product_obj->save();
}
}
// Kutsu funktio
add_action('init', 'adjust_and_round_prices');
Editor is loading...
Leave a Comment