Skip to content

Instantly share code, notes, and snippets.

@nayemDevs
Last active January 31, 2019 20:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nayemDevs/e2867e57ec57fd96fb12791f8b29fc77 to your computer and use it in GitHub Desktop.
Save nayemDevs/e2867e57ec57fd96fb12791f8b29fc77 to your computer and use it in GitHub Desktop.
/* global shipping for each seller into the seller profile */
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) {
$country_obj = new WC_Countries();
$countries = $country_obj->countries;
$states = $country_obj->states;
$processing_time = dokan_get_shipping_processing_times();
$dps_enable_shipping = get_user_meta( $user->ID, '_dps_shipping_enable', true );
$dps_shipping_type_price = get_user_meta( $user->ID, '_dps_shipping_type_price', true );
$dps_additional_product = get_user_meta( $user->ID, '_dps_additional_product', true );
$dps_additional_qty = get_user_meta( $user->ID, '_dps_additional_qty', true );
$dps_pt = get_user_meta( $user->ID, '_dps_pt', true );
$dps_shipping_policy = get_user_meta( $user->ID, '_dps_ship_policy', true );
$dps_refund_policy = get_user_meta( $user->ID, '_dps_refund_policy', true );
$dps_form_location = get_user_meta( $user->ID, '_dps_form_location', true );
?>
<h3>Dokan Shipping</h3>
<table class="form-table">
<tr>
<th><label for="shipping">Enable Shipping</label></th>
<td>
<label>
<input type="hidden" name="dokan_enable_shipping" value="no">
<input type="checkbox" name="dokan_enable_shipping" value="yes" <?php checked( 'yes', $dps_enable_shipping, true ); ?> >
</label>
<span class="description">Enable shipping for this seller</span>
</td>
<tr>
<th><label for="price">Default Shipping Price </label></th>
<td>
<input type="text" name=" dps_shipping_type_price" value="<?php echo $dps_shipping_type_price; ?>" placeholder="0.00" type="number" step="any" min="0">
</td>
</tr>
<tr>
<th><label for="additional_product">Per Product Additional Price </label></th>
<td>
<input type="text" name="dps_additional_product" value="<?php echo $dps_additional_product; ?>" placeholder="0.00" type="number" step="any" min="0">
</td>
</tr>
</tr>
<tr>
<th><label for="additional_qty_product">Per Qty Additional Price </label></th>
<td>
<input type="text" name="dps_additional_qty" value="<?php echo $dps_additional_qty; ?>" placeholder="0.00" type="number" step="any" min="0">
</td>
</tr>
<tr>
<th><label for="processing_time">Processing Time</label></th>
<td>
<select name="dps_pt" id="dps_pt" class="dokan-form-control">
<?php foreach ( $processing_time as $processing_key => $processing_value ): ?>
<option value="<?php echo $processing_key; ?>" <?php selected( $dps_pt, $processing_key ); ?>><?php echo $processing_value; ?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr>
<th><label for="shipping_policy">Shipping Policy </label></th>
<td>
<textarea name="dps_ship_policy" id="" class="dokan-form-control"><?php echo $dps_shipping_policy; ?></textarea>
</td>
</tr>
<tr>
<th><label for="refund_policy">Refund Policy </label></th>
<td>
<textarea name="dps_refund_policy" id="" class="dokan-form-control"><?php echo $dps_refund_policy; ?></textarea>
</td>
</tr>
<tr>
<th><label for="refund_policy">Shipping From </label></th>
<td>
<select name="dps_form_location" class="dokan-form-control">
<?php dokan_country_dropdown( $countries, $dps_form_location ); ?>
</select>
</td>
</tr>
</tr>
</table>
<?php
}
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
/* update user meta */
update_usermeta( $user_id, '_dps_shipping_enable', $_POST['dokan_enable_shipping'] );
update_usermeta( $user_id, '_dps_shipping_type_price', $_POST['dps_shipping_type_price']);
update_usermeta( $user_id, '_dps_additional_product', $_POST['dps_additional_product']);
update_usermeta( $user_id, '_dps_additional_qty', $_POST['dps_additional_qty']);
update_usermeta( $user_id, '_dps_pt', $_POST['dps_pt']);
update_usermeta( $user_id, '_dps_ship_policy', $_POST['dps_ship_policy']);
update_usermeta( $user_id, '_dps_refund_policy', $_POST['dps_refund_policy']);
update_usermeta( $user_id, '_dps_form_location', $_POST['dps_form_location']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment