我运行一个wooocommerce网站,重量是磅,我需要将它们转换为公斤.
我已经从一个网站下载了这个脚本,它完成了这个工作,但是它设置了很多小数的新权重,不知道如何舍入它.
我试图使用,round($new_weight, 2);但它没有采取或不确定在何处放置它或如何.
注意:我对php一无所知.此脚本是页面模板.它会在您打开它时进行更改.
<?php
/*
*
* Template name: wconvertor
*/
get_header();
$args = array( 'post_type' => 'product', 'posts_per_page' => 2500 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$weight= get_post_meta( get_the_ID(), '_weight', true);
if ( ! empty( $weight ) ) {
echo "id = ".get_the_ID(). " weight = ".$weight;
$new_weight = $weight / 2.2 ;
round($new_weight,2);
echo "<br>new weight = ".$new_weight." ********************";
// id , key , …Run Code Online (Sandbox Code Playgroud)