Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.2 kB
9
Indexable
Never

add_filter( 'request', 'process_admin_shop_order_marketing_by_meta', 99 );
add_filter( 'woocommerce_order_list_table_prepare_items_query_args',  'process_admin_shop_order_marketing_by_meta', 99 );

function process_admin_shop_order_marketing_by_meta( $vars ) {

	$user_id = 1234;

    global $pagenow, $typenow;
    
    $filter_id = 'filter_shop_order_by_meta';

    $show = false;
    if( 'shop_order' === $typenow && 'edit.php' === $pagenow ) {
    	$show = true;
    }
    if (isset($_GET['page'])){
    	if ($_GET['page'] === 'wc-orders'){
    		$show = true;
    	}
    }
    
    if ($show){
    	if (get_current_user_id() == $user_id){
		    $vars['meta_key']   = 'b2bking_is_b2b_order';
			$vars['meta_value']   = 'yes';
			$vars['meta_compare']  = '=';
    	}

    }
    
    return $vars;
}

add_action('woocommerce_checkout_order_processed',  'b2bking_update_order_data', 10 );
function b2bking_update_order_data( $order_id ) {
	$order = wc_get_order($order_id);

	// add b2b marker if b2b order
	$customer_id = $order->get_customer_id();
	$is_b2b = get_user_meta($customer_id,'b2bking_b2buser', true);
	if ($is_b2b === 'yes'){
		$order->update_meta_data( 'b2bking_is_b2b_order', 'yes' );
	}

	$order->save();
}