日数の差を求める
-
初めまして。
現在、簡単な入出庫管理システムをWordPressで構築しています。システム上、ある一定の日数をすぎると超過料金が発生するため、「入庫日($arrival_data)」と「出庫日($ship_data)」の差を求めたく、色々と調べて以下のようなphpをfunction.phpに入力しているのですが、「// arrival_dataとship_dataの日数の差を計算」のところがうまくいっていないようで「0」が返ってきてしまいます。そこ以外の計算はうまく動いているようです。
PHPは素人なので、これ以上の原因がわからず…
どなたか力を貸していただけないでしょうか。WordPressは5.4.2、使用テーマはStp Accessibilityです。
また、投稿の入力フィールドはACFを使ってカスタム投稿フィールドにしていて、$ship_dataと$arrival_dataはデイトピッカーを使用しています。
どうぞよろしくお願いいたします。<?php
//金額の計算
function save_post_meta( $post_ID, $post, $update ) {
$post_type = get_post_type( $post_ID );if ( “post” != $post_type )
return;// Subtotal1の自動計算
$weight = get_post_meta( $post_ID,’weight’, true );
$sub_total1 = $weight * 100 ;
update_post_meta( $post_ID, ‘sub_total1’, $sub_total1 );// arrival_dataとship_dataの日数の差を計算
$time1 = strtotime($ship_data);
$time2 = strtotime($arrival_data);
$difference = ($time1 – $time2) / (60 * 60 * 24);
update_post_meta( $post_ID, ‘difference’, $difference );// 延長料金を計算
$sub_total2 = ($difference – 3) * $weight * 100 ;
update_post_meta( $post_ID, ‘sub_total2’, $sub_total2 );// 合計の自動計算
$total_fee = $sub_total1 + $sub_total2 ;
update_post_meta( $post_ID, ‘total_fee’, $total_fee );}
add_action( ‘save_post’, ‘save_post_meta’, 10, 3 );
?>
- トピック「日数の差を求める」には新たに返信することはできません。