Настройка плагина Dokan для добавления функции минимального значения заказа - PullRequest
0 голосов
/ 23 апреля 2020

Я хочу добавить новую опцию для плагина 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 );
}


//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() ) {


add_filter( 'woocommerce_get_item_data', 'wc_add_minimum_order_to_cart', 10, 2 ); 
function wc_add_minimum_order_to_cart( $other_data, $cart_item ) { 
$post_data = get_post( $cart_item['product_id'] ); 
$post_data->post_author; 
$vendor_id = $post_data->post_author;
    echo '<br>';


// HERE Set minimum cart total amount
$min_total = 'minimum_order: ';
echo $test;
$user_id = $vendor_id;

// Get all user meta data for $user_id
$meta = get_user_meta( $user_id );

// Filter out empty meta data
$meta = array_filter( array_map( function( $a ) {
    return $a[0];
}, $meta ) );

echo $min_total;
print_r( $meta['_minimum_order'] );


// 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' );
     }
}
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...