Add the below line in wp-config.php
ini_set('display_errors','Off');ini_set('error_reporting', E_ALL );define('WP_DEBUG', false);define('WP_DEBUG_DISPLAY', false);
Add the below line in wp-config.php
ini_set('display_errors','Off');ini_set('error_reporting', E_ALL );define('WP_DEBUG', false);define('WP_DEBUG_DISPLAY', false); // Checking the pincode of shipping and adding in assigning to fulfilment-partner
function before_checkout_create_order($order, $data)
{
$args1 = array('role__in' => array('fulfilment_partner') );
$shipping_pincode = $order->shipping_postcode;
$users = get_users( $args1 );
// Array of WP_User objects.
foreach ( $users as $user ) {
$stpax = explode(',',trim($user->stokist_pincode_allocated));
if (in_array($shipping_pincode,$stpax)) {
$store_manager_id = $user->id ;
}
}
$order->update_meta_data('_store_manager_id', $store_manager_id);
}
add_action('woocommerce_checkout_create_order', 'before_checkout_create_order', 20, 2);
//Showing the order according to fulfilment partner wise.
function custom_admin_shop_manager_orders($query)
{
global $pagenow;
$qv = &$query->query_vars;
$currentUserRoles = wp_get_current_user()->roles;
$user_id = get_current_user_id();
//if (in_array('shop_manager',$currentUserRoles)) {
if($currentUserRoles[0] == 'fulfilment_partner')
{
if ( $pagenow == 'edit.php' && isset($qv['post_type']) && $qv['post_type'] == 'shop_order' ) {
// I use the meta key from step 1 as a second parameter here
$query->set('meta_key', '_store_manager_id');
// The value we want to find is the $user_id defined above
$query->set('meta_value', $user_id);
}
}
return $query;
}
add_filter('pre_get_posts', 'custom_admin_shop_manager_orders');
//Pincode starts here.
add_action( 'show_user_profile', 'show_extra_profile_fields' );
add_action( 'edit_user_profile', 'show_extra_profile_fields' );
function show_extra_profile_fields( $user ) {
if(is_user_logged_in() ) {
$user = wp_get_current_user();
$user->roles[0];
if ($user->roles[0] == 'administrator') { ?>
<table class="form-table">
<tr>
<th><label for="contact">Pincode Assigned</label></th>
<td>
<textarea name="stokist_pincode_allocated" id="stokist_pincode_allocated" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'stokist_pincode_allocated', $user->ID ) ); ?></textarea><br />
<span class="description">Please enter your Pincode.</span>
</td>
</tr>
</table>
<?php } } }
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
function save_extra_profile_fields( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_usermeta( $user_id, 'stokist_pincode_allocated', esc_attr( $_POST['stokist_pincode_allocated'] ) );
}
//Removing extra fields from profile page. User description, outlet, address, url
function remove_website_row_wpse(){
echo '<style>tr.user-url-wrap{ display: none; }</style>';
echo '<style>tr.user-description-wrap{ display: none; }</style>';
echo '<style>tr.OutletName{ display: none; }</style>';
echo '<style>tr.Address{ display: none; }</style>';
}
add_action( 'admin_head-user-edit.php', 'remove_website_row_wpse' );
add_action( 'admin_head-profile.php', 'remove_website_row_wpse' );
//Removing extra field name company from checkout page.
function remove_company_name_from_checkout( $fields ) {
unset( $fields['billing_company'] );
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'remove_company_name_from_checkout' );
endif;