我在Dokan new-single-product.php模板中创建了一个自定义复选框元:
< div class =“dokan-form-group”> < div class =“dokan-input-group”> <?php dokan_post_input_box($ post_id,’…
关于这一点还有更多的文章,我一直在想我的问题是不同的,但是我做了以下几点并使用我在其他帖子上找到的一般解决方案修复了它:
检查一下 的 元价值 强> 实际上是存储在数据库中的 的 元键 强> 。
检查get_post_meta方法的参数是可读的方法(在我的情况下$ item_id无效,该方法需要产品的实际帖子ID)
检查条件实际上是否使用了正确的值:if($ custom_field ==“yes”)
foreach函数的最终代码:
foreach ( $order->get_items() as $item_id => $item ) { $product_id = $item->get_product_id(); $custom_field = get_post_meta( $product_id, '_custom_field', true ); $line_total = $item->get_total(); if( $custom_field == "yes" ) { $amount += $line_total; } }