我想在我的 Dokan 商店有一个最低订单量。以下代码正在工作,但个别供应商无法选择自己的最小值。
//minimum order value
add_action( 'woocommerce_check_cart_items', 'required_min_cart_subtotal_amount' );
function required_min_cart_subtotal_amount() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
// HERE Set minimum cart total amount
$min_total = 200;
// Total (before taxes and shipping charges)
$total = WC()->cart->subtotal;
// Add an error notice is cart total is less than the minimum required
if( $total <= $min_total ) {
// Display an error message
wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($min_total) ) . '<strong>', 'error' );
}
}
}
所以我在 Dokan 设置页面添加了一个自定义字段
//Extra field on the seller settings and show the value on the store banner -Dokan
// Add an extra field in seller settings
add_filter( 'dokan_settings_form_bottom', 'extra_fields', 10, 2);
function extra_fields( $current_user, $profile_info ){
$minimum_order= isset( $profile_info['minimum_order'] ) ? $profile_info['minimum_order'] : '';
?>
<div class="gregcustom dokan-form-group">
<label class="dokan-w3 dokan-control-label" for="setting_address">
<?php _e( 'Minimum order value', 'dokan' ); ?>
</label>
<div class="dokan-w5">
<input type="number" class="dokan-form-control input-md valid" name="minimum_order" id="reg_minimum_order" value="<?php echo $minimum_order; ?>" />
</div>
</div>
<?php
}
//save the field value
add_action( 'dokan_store_profile_saved', 'save_extra_fields', 15 );
function save_extra_fields( $store_id ) {
$dokan_settings = dokan_get_store_info($store_id);
if ( isset( $_POST['minimum_order'] ) ) {
$dokan_settings['minimum_order'] = $_POST['minimum_order'];
}
update_user_meta( $store_id, 'dokan_profile_settings', $dokan_settings );
}
现在我想在这里使用一些代码,
$min_total = 200;
从购物车的物品中获取供应商 ID,并使用它来获取用户元数据并在上面显示 minimum_order 值。(200) 对不起我的英语不好。