【发布时间】:2019-03-01 13:38:38
【问题描述】:
在 WooCommerce 中,我使用工具集类型向产品添加了 2 个字段。因此,当您添加产品时,您可以将预计交货时间设置为天或周。
在购物车和评论页面上,我编写了一些代码来显示总计表中的最长交货时间。
我已经在 cart-totals.php 和 review-order.php 的结束表标记之前添加了以下代码(当然我已经将它添加到我的子主题中)。
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
$amount_of_days = 0;
$delivery_amount = get_post_meta($product_id, 'wpcf-aantal', true);
$delivery_week_or_days = get_post_meta($product_id, 'wpcf-dagen-of-weken', true);
if($delivery_week_or_days == "weken"){
$amount_of_days = $delivery_amount * 7;
} else {
$amount_of_days = $delivery_amount;
}
$array_of_days[] = $amount_of_days;
}
$most_days = max($array_of_days);
if ($most_days % 7 == 0){
$most_time_string = $most_days/7 . ' weken';
} else {
$most_time_string = $most_days . ' dagen';
}
if (!empty($most_days)){
echo '<tr class="custom-cart-delivery-time">';
echo '<th>Geschatte levertijd</th>';
echo '<td>' . $most_time_string. '</td>';
echo '</tr>';
}
我的问题是我如何才能真正保证这个订单的安全?我希望在订单和发票中显示预计的运输时间(例如:“3 周”或“2 天”)。
【问题讨论】:
标签: php wordpress woocommerce metadata orders